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
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 5 May 2017, 7:24 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
Quote:
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:

Code:
$ s=`echo 'abc def'|grep 'xxx'`
$ echo $?                      
1
$ s=`echo 'abc def'|grep 'abc'`
$ echo $?                      
0