Using XPath in bash with not()
The $()
construct substitutes the output of the command. As such, whatever is spit out by xpath
will be substituted and the shell will try to execute that as a command which is why you get the error message.
Since xpath
doesn't seem to provide a different exit code based on whether a node was found, you will probably just have to compare the output to something, or test for empty:
if [ -z "$(xpath -q -e '//otherFile' "$f" 2>/dev/null)" ]; then
This should execute the following code if xpath
produced no output. To reverse the sense, use -n
instead of -z
(not sure which one you intended).