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
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 22 September 2017, 9:14 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,572
Thanks: 175
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 $().