I want to grep
for a string and cut a field if there is a match. Problem is that, no matter if there is a match or not, the output of the command $?
is 0 which is weird. Please see the output below:
$ R=`grep g09 tor1.sh | cut -d ' ' -f2`
$ echo $R
test
$ R=`grep g09 tor1.sh | cut -d ' ' -f2`
$ echo $?
0
As you can see, there is a match but $?
is 0. Now see this:
$ R=`grep g09 tor.sh | cut -d ' ' -f2`
$ echo $R
$ R=`grep g09 tor.sh | cut -d ' ' -f2`
$ echo $?
0
Here, there is no match for g09 but $?
is still 0. Why?