user1011046
user1011046

Reputation: 204

error using "find" command in unix

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...

Upvotes: 2

Views: 9680

Answers (1)

Anya Shenanigans
Anya Shenanigans

Reputation: 94654

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.

Upvotes: 4

Related Questions