Shell script snippet:
tagSearch= $(grep '^\#ctags$' ./"$1" | wc -l)
if [[ $tagSearch -ne "0" ]]
then
...
fi
Results in:
line 2: /bb/bin/1: Permission denied
Context:
I’m trying to detect whether a particular pattern exists in a file so I can take a particular action.
I understand the error I’m getting, the detection is working but the script is trying to evaluate the result ‘1’ and run the program ‘1’ in my path. This isn’t what I want. How do I get the behavior I’m looking for?
Variable assignments in the bash shell should not have a space after the equals. Actually it should never have whitespace in it at all. See below.
Not important to your error but also of note, when using the double bracket syntax, you don’t need to quote that zero any more than the variable you are comparing it with.
Actually your whole code could be re-factored using
grep‘s quite mode and evaluating the return code to see if you got any matches: