[英]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.