2012-01-09 49 views
1

當我做了以下find覆蓋index.html我可以預期它只會附加其結果。如何結合回聲和查找?

echo "<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head></body>" > index.html 

find . -name "*.html" -exec echo "<a href=\"{}\">{}</a><br/>" \; >> index.html 

這是假設找到所有的html文件並創建它們的索引。

有沒有人如何做到這一點,理想情況下不使用臨時文件?

+0

你試過'-printf'? – l0b0 2012-01-09 11:17:23

回答

2

問題是在你的回聲線,回聲線應該是:

echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head></body>' > index.html 

你有"你的文字裏和你的echo命令邊界爲好。

+2

我也覺得''應該是一個oponing標籤'',另一個'echo'在需要在'find'輸出追蹤'' – 2012-01-09 11:15:01

2

你要逃避所有「字回聲。

echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head></body>" > index.html 

find . -name "*.html" -exec echo "<a href=\"{}\">{}</a><br/>" \; >> index.html