help-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: Greg Wooledge
Subject: Re: [Help-bash] difference of $? and ${PIPESTATUS[0]}
Date: Wed, 4 Dec 2013 14:40:11 -0500
User-agent: Mutt/1.4.2.3i

On Wed, Dec 04, 2013 at 07:33:32PM +0000, adrelanos wrote:
> when writing bash scripts, are there situations where it's better to use
> "$?" instead of "${PIPESTATUS[0]}"?

The most obvious difference is that $? is shorter.

$? is also POSIX standard (older than POSIX in fact), so it works in sh
scripts as well.  PIPESTATUS is a Bash extension.

Finally, note that if you execute a pipeline, $? will contain the exit
status of the last command in the pipeline, not the first command,
which is what ${PIPESTATUS[0]} would contain.  (If you execute a simple
command instead of a pipeline, then they would both have the same value.)



reply via email to

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