dimanche 2 août 2020

bash shell script if/then: how to properly test a set of grep statements return with exit code 0 [duplicate]

I'm struggling to properly construct a bash script if / then statement that allows me to test for the presence of a set of strings using grep within a target file. I know at this point I'm doing this wrong with regard to expecting the return code to properly compare using brackets, I'm just not sure how to do this properly.

Note in the example below I've switched back and forth between = 0 and -ne 0 to no avail...

if [[ $(grep -Fxq "something = setting" /path/to/file.txt) = 0 ]] && [[ $(grep -Fxq "something2 = setting2" /path/to/file.txt) = 0 ]] && [[ $(grep -Fxq "something3 = setting3" /path/to/file.txt) = 0 ]]
   then
       printf "the strings you are looking for are present \n"
   else
       printf "the strings you are looking for are NOT PRESENT \n"
fi

Aucun commentaire:

Enregistrer un commentaire