简体   繁体   English

猫:无效选项 - 'a'

[英]cat: invalid option — 'a'

I have some c files and common.txt in "Abb/test" folder and temp.txt in "Abb" folder.I want to copy content of common.txt in header of all the c files. 我在“Abb / test”文件夹中有一些c文件和common.txt,在“Abb”文件夹中有temp.txt。我想在所有c文件的头文件中复制common.txt的内容。 I am using the following unix shell script code:- 我使用以下unix shell脚本代码: -

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

but it is giving error "cat: invalid option -- 'a' " 但它给出了错误“cat:invalid option - 'a'”
can someone help me out. 有人可以帮我吗。

You have several grave problems in your code. 您的代码中存在几个严重问题。

Your code with newlines for readability: 您的代码带有可读性换行符:

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

Problem: wrong quotes for shell substitution. 问题:shell替换的引号错误。

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

Problem: not quoting $i . 问题:没有引用$i

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

Problem: using for loop to loop over filenames. 问题:使用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