Strange behaviour surrounding "ssh -T ..." and non-zero exit

u-pwhy at aetey.se u-pwhy at aetey.se
Sat Nov 10 20:25:26 AWST 2018


On Sat, Nov 10, 2018 at 10:44:03AM +0100, Peter Krefting wrote:
> >$ echo false | dbclient -T root at host.example.com
> >$ echo $?
> >0
> 
> That is because $? contains the exit status of the left-most command (echo),
> not the pipe. If you are using a bash shell, you need to use PIPESTATUS to
> find it, read more at: https://unix.stackexchange.com/a/73180

I feel this deserves correction and clarification, because it is possible
to encounter contradicting statements from different sources.

Long ago the status reporting from a shell pipe was a contentious
issue, the rules varied with time and between different shells.

Nowadays it is consistent, reporting the status of the _last_ command
in the pipe:

$ false | true; echo "$?"
0
$ true | false; echo "$?"
1

The cited link above discusses reporting of status from some member of
the pipe which is _not_ the rightmost, in a modern shell.

Cheers,
Rune



More information about the Dropbear mailing list