./a.out && echo $? only prints return value if return = 0
1
vote
1
answer
1054
views
*echo $?* in the following scenario does not display the return value, i.e. 1.
echo "int main() { return 1; }" > foo.c
gcc foo.c && ./a.out && echo $?
However, *echo $?* works when the program returns 0. Why is this?
Note: If you do another *echo $?* after the code above, you get the desired output 1.
Asked by Harvinder
(395 rep)
Sep 15, 2014, 08:03 PM
Last activity: Sep 16, 2014, 02:31 PM
Last activity: Sep 16, 2014, 02:31 PM