bash - How to retrieve the return code of a command in a short-circuit expression -
after expression:
command1 | command2
i can retrieve first commands exit status through ${pipestatus[0]}
is there equivalent expressions in form:
command3 && command4 || command5
i retrieve exitcode of command3:
command3 && command4 || command5 retval=${shortcircuit[0]} # how value?
preferably without creating temporary files.
elaborating devnull's approach leads to
{ c3=0; command3 || c3=$? && false; } && command4 || command5 echo $c3
. because every command
can replaced by
{ c=0; command || c=$? && false; }
(provided c
unset if executed conditionally), extensible.
Comments
Post a Comment