我在"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:无效选项-- a“
有人能帮帮我吗。
发布于 2015-02-05 11:37:17
您的代码中有几个严重问题。
您的代码具有新行以提高可读性:
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发布于 2017-04-21 01:18:26
在执行自定义上传的shell脚本时,尝试使用cp命令时也出现了类似的错误,经过大量时间的搜索,我最终发现我的脚本文件中有unix format,并将它们转换为unix format,解决了问题。
https://stackoverflow.com/questions/28342632
复制相似问题