please help me with this.
I am doing a grep test file.txt and I want to catch the whole value and print it.I am doing this,
grep test file.txt if [ "$?" -eq 0] then echo success else echo fail fi
In this code, whether the grep returns a value or not always the exit code is 0 as the command is successful.
I do not want to do the following as my actual code has repetitive greps, say 10 times and it is not working.
a=`grep test file.txt` if [ "$a" -eq "" ] then echo fail else echo success fi
I am looking for a simple solution like this,
echo $(anything) should catch the value.