error using “find” command in unix

这一生的挚爱 提交于 2020-03-04 05:09:25

问题


I was just trying the below code and it is not working.. please suggest to correct this code..

echo abc.txt | while read name; do find . -name $name; done

output success : ./rak/abc.txt

echo 'abc.txt pqr.txt' | while read name; do find . -name $name; done

output error : find: 0652-009 There is a missing conjunction

echo "abc.txt pqr.txt" | while read name; do find . -name $name; done

output error : find: 0652-009 There is a missing conjunction

same error with

echo "abc.txt" "pqr.txt" | while read name; do find . -name $name; done
echo 'abc.txt' 'pqr.txt' | while read name; do find . -name $name; done

Please suggest how to resolve this problem...


回答1:


The problem is that the multiple entries are sent into the pipe as one line, the read picks up both strings into name and then processes the $name containing the two strings.

You should use something like:

echo -e "abc.txt\npqr.txt" | while read name; do find . -name $name; done

i.e. separate the items with a newline.

You should have tried debugging this by using echo "'$name'" instead of the find and it would have hinted what was happening.

Additionally, I would use quoting around the use of $name in the find, as if the filename is expected to have a space in it's name then you will get the same error message as you have experienced originally.



来源:https://stackoverflow.com/questions/11308436/error-using-find-command-in-unix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!