bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to deal with errors in <()?


From: Peng Yu
Subject: Re: How to deal with errors in <()?
Date: Sat, 14 Mar 2015 14:37:34 -0500

On Sat, Mar 14, 2015 at 8:46 AM, Linda Walsh <bash@tlinx.org> wrote:
>
>
> 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)

Stdout and stderr are commonly used for other purposes. But using fd 3
and above seems to be a good walkaround. Does anybody have a cleaner
solution?

> 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
>
>



-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]