Sam Roberts
Sam Roberts

Reputation: 399

find in a shell script gives an unknown predicate `-v' error

find in a shell script gives an unknown predicate `-v' error

Output:

/bin/find /home/dev/public_html/ | grep -v "^secure" | grep -v "^folder1/folder2"
/bin/find: unknown predicate `-v'

Code:

FINDP="  | grep -v \"^secure\" | grep -v \"^folder1/folder2\""
echo "/bin/find /home/dev/public_html/$FINDP";
`/bin/find /home/dev/public_html/$FINDP`

Any ideas how to fix this? (The idea is to store the results from the backticks in a variable later.)

Upvotes: 0

Views: 4619

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80992

You can't store complex commands in strings. It doesn't work. This is Bash FAQ 050.

Specifically in your case the shell doesn't see | as a shell pipeline but instead as a regular character and so find sees the -v argument to grep and complains.

Upvotes: 2

Related Questions