Unix/Linux Go Back    

Exit status of grep

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member zaxxon Regarding:
Exit status of grep.
Please Follow The Primary Link Above to View the Full Discussion.

Old Unix and Linux 03-09-2010   -   Original Discussion by prasbala
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 15 November 2017, 7:27 AM EST
Location: St. Gallen, Switzerland
Posts: 6,574
Thanks: 176
Thanked 560 Times in 481 Posts
Assigning the substituted output of a command to a variable will simply contain it's output, ie. the pattern grep -o found or not. It does not contain the return code of the grep!

Use Franklins example since it is the only one of that cares for the exit code which is checked by $? immediately after the command you want to observe.

It doesn't have anything to do with the type of how it is substituted ie. double `or $().