簡體   English   中英

貓:無效選項 - 'a'

[英]cat: invalid option — 'a'

我在“Abb / test”文件夾中有一些c文件和common.txt,在“Abb”文件夾中有temp.txt。我想在所有c文件的頭文件中復制common.txt的內容。 我使用以下unix shell腳本代碼: -

for i in 'find test -name *.c'; do cat test/common.txt $i > temp.txt && mv temp.txt $i; done

但它給出了錯誤“cat:invalid option - 'a'”
有人可以幫我嗎。

您的代碼中存在幾個嚴重問題。

您的代碼帶有可讀性換行符:

for i in 'find test -name *.c'
do
  cat test/common.txt $i > temp.txt && mv temp.txt $i
done

問題:shell替換的引號錯誤。

for i in `find test -name '*.c'`
do
  cat test/common.txt $i > temp.txt && mv temp.txt $i
done

問題:沒有引用$i

for i in `find test -name '*.c'`
do
  cat test/common.txt "$i" > temp.txt && mv temp.txt "$i"
done

問題:使用for循環遍歷文件名。

find test -name '*.c' | while read -r filename
do
  cat test/common.txt "$filename" > temp.txt && mv temp.txt "$filename"
done

我在嘗試使用cp命令執行我的自定義上傳的shell腳本時遇到了類似的錯誤,經過大量時間搜索原因我終於發現我的腳本文件有windows line endings並在將它們轉換為unix format后問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM