Posts

Showing posts from April 3, 2019

Catching the last returned value in Unix

Image
Clash Royale CLAN TAG #URR8PPP 0 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. shell-script share | improve this question edited Mar 6 at 16:23 Rui F Ribeiro 41.9k 14 83 142 asked Feb 4 '16 at 17:28 ramesh ramesh 1 1 Are you doing like foo | grep bar | grep baz and you need to know if an arbitrary grep failed/succeeded ( set -o pipefail ), or you want to save...