Peng Yu wrote:
Hi, http://mywiki.wooledge.org/ProcessSubstitution The above webpage says the following. commandA <(commandB; [commandB's exit code is available here from $?]) [commandB's exit code cannot be obtained from here. $? holds commandA's exit code]
Does anybody have a good solution for this situation? Thanks.
-- It's not a pretty solution, but how about some variation of:
alias cmda='cat >/dev/tty' ## 1st cmd alias cmdb='(echo "foo";exit 2)' ## command executes, but exits w/err=2 read status < <(cmda <(cmdb; echo "status=$?" >&2) 2>&1)
status=2 foo --- not ideal, but it does get you the status. Instead of echoing it you could assigned it to a var, and test the value and only print status if non-zero, something like: ((status=$?)) && echo "status=$status instead of just the echo