bug-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] difference of $? and ${PIPESTATUS[0]}


From: felix
Subject: Re: [Help-bash] difference of $? and ${PIPESTATUS[0]}
Date: Mon, 22 Apr 2024 09:15:52 +0200

Le Mon, Apr 22, 2024 at 07:44:48AM +0100, Kerin Millar a écrit :
> On Mon, 22 Apr 2024, at 7:13 AM, felix wrote:
> > ...
> >   if ls /wrong/path | wc | cat - /wrong/path | sed 'w/wrong/path' 
> > >/dev/null ; then
> >       echo Don't print this'
> >   fi ; echo ${?@Q} ${PIPESTATUS[@]@A}  $(( $? ${PIPESTATUS[@]/#/+} ))
> >
> >   ls: cannot access '/wrong/path': No such file or directory
> >   cat: /wrong/path: No such file or directory
> >   sed: couldn't open file /wrong/path: No such file or directory
> >   '0' declare -a PIPESTATUS=([0]="2" [1]="0" [2]="1" [3]="4") 7
> >
> > Where $PIPESTATUS[0]=>2 and $?=>0 !!
> > ...
> > If so, "$?" have to be equivalent to "${PIPESTATUS[0]}", I think.
> 
> No. That would only be true in the event that the pipeline comprises a single 
> command. The present documentation is correct.

I was wrong: the last is `${PIPESTATUS[-1]}' -> '${PIPESTATUS[3]}' in this case,
anyway
         $PIPESTATUS[3]=>4 and $?=>0 !!

> It's worth reading the section of the manual that concerns "Pipelines".
Reading this, if I could understand why
  false;echo ${PIPESTATUS[0]} $?
  1 1
I'm still don't be able to explain this:
  if false;then echo Don't print that's;fi; echo ${PIPESTATUS[0]} $?
  1 0

-- 
 Félix Hauri  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch



reply via email to

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