Unix/Linux Go Back    

Exit status of grep

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member Franklin52 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
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
Join Date: Feb 2007
Last Activity: 14 October 2017, 3:52 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
Originally Posted by frans View Post
The variable contains the output but the return code corresponds to the return code of the last command (grep). Try to print $? and you'll see what happens.
This is what happens:

$ s=`echo 'abc def'|grep 'xxx'`
$ echo $?                      
$ s=`echo 'abc def'|grep 'abc'`
$ echo $?