5 ms·
That's correct behavior though. You should do if ARG=false Then use $ARG not $? in the if statement.
by nikau 4y ago
That's correct behavior though.
You should do
if ARG=false
Then use $ARG not $? in the if statement.
- dataflow 4y agoIt's the best kind of correct, yes.
- nikau 4y agoIt's a pretty bizarre use case, why would you need the second if statement, you already are in logic based on the return code I can't think of an example of the if statement being confusing that isn't relying on $?
- dataflow 4y agoerror=0 if ! some_command; then error=$?; bar; fi echo "blah" return $error
- nikau 4y agoYep that's a valid scenario, if you need more granularity than just fail or success then you will have to use a different method, e.g. Status=0 Somecommand || status=$? Then do logic based on status