Re: [Help-bash] Is there a way to swap stdout with stderr?
From:
Dmitry Alexandrov
Subject:
Re: [Help-bash] Is there a way to swap stdout with stderr?
Date:
Tue, 26 Jul 2016 01:08:10 +0300
User-agent:
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)
Bob Proulx <bob-5cAygf9QrE/address@hidden> writes:
> Eduardo A. Bustamante López wrote:
>> Peng Yu wrote:
>> > Hi, I want to swap stdout and stderr of a command. I.e., I want to
>> > print the output of stdout to stderr and the output of stderr to
>> > stdout. Is there is a way to do so?
>>
>> I'd do something like:
>>
>> | command 3>&1 1>&2 2>&3
>>
>> The fd #3 works as a temporary variable to help in the swap.
>
> And then 3>&- to close the temporary 3 to complete the cleanup. :-)
>
> command 3>&1 1>&2 2>&3 3>&-
>
Or even its four chars shorter and pretty much obscure equivalent:
command 3>&1 1>&2 2>&3-
:-)