Recursion 递归地对目录中的每个文件运行脚本,并将每个输出传递到新文件

Recursion 递归地对目录中的每个文件运行脚本,并将每个输出传递到新文件,recursion,find,markdown,Recursion,Find,Markdown,我正在尝试使用本机markdown.pl--html4tags脚本将~/notes/(及以下)中的每个.markdown文件转换为html。但是,Markdown.pl将html打印为stout,这意味着要将test.Markdown转换为test.html,我需要运行:Markdown.pl--html4tags test.Markdown>test.html 我一直在想如何将管道合并到递归的find-exec或find…|xargs函数。我想到的最好的办法是: for i in `find

我正在尝试使用本机
markdown.pl--html4tags
脚本将
~/notes/
(及以下)中的每个
.markdown
文件转换为html。但是,
Markdown.pl
将html打印为stout,这意味着要将
test.Markdown
转换为
test.html
,我需要运行:
Markdown.pl--html4tags test.Markdown>test.html

我一直在想如何将管道合并到递归的
find-exec
find…|xargs
函数。我想到的最好的办法是:

for i in `find ~/notes/ -type f -name "*.markdown"` ; do
  Markdown.pl --html4tags $i > ${i}.html ;
done
它成功地将每个
.markdown
文件转换为html,但它看起来当然像
test.markdown.html
而不是
test.html

所以基本上,我需要做一些事情,比如将
${I}.markdown
转换为
${I}.html
,但我不知道如何在函数中对其进行编码。谢谢你的帮助

edit:我找到了一种修复上述脚本的方法,使用
basename
(我刚刚发现):

这基本上会将每个
.markdown
文件转换为html,同时也会剥离
.markdown
扩展名,然后添加
.html
扩展名

我很想知道是否有更好的方法,例如使用
find-exec

Boom

find~/notes/-name'*.markdown'|同时读取行
做
Markdown.pl--html4tags$line>${line/.Markdown/.html}
完成
for i in `find ~/notes/ -type f -name "*.markdown"` ; do
  Markdown.pl --html4tags $i > `basename $i .markdown`.html ;
done