When testing the exit status of a command (e.g. grep
), you don't need or want [[ ]]
or $( )
or any of that stuff. if
checks the exit status of whatever's between if
and then
, and takes the appropriate branch based on whether it succeeded or failed.
$( )
exists to capture the output of a command (i.e. what it prints as it runs -- grep -q
does not print anything), and use it as part of another command. That's not what you want at all.
[[ ]]
evaluates a test expression (which can test whether e.g. a file exists, whether two strings are equal, etc), and converts the result into an exit status. But with grep -q
it's already producing an exit status, so you don't need some sort of test to get it into that form.
You do need [[ ]]
to check whether file_a exists, but that's the only role it'll play here. And you need &&
to make a compound command that succeeds only if all parts of it succeed. So what you want is:
...
if [[ -f file_a ]] &&
grep -q "b" file_b &&
grep -q "c" file_c; then
...