bug-bash
[Top][All Lists]
Advanced

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

Re: Bad PIPESTATUS when using eval with a pipe stored in a variable


From: Chet Ramey
Subject: Re: Bad PIPESTATUS when using eval with a pipe stored in a variable
Date: Thu, 30 Jun 2005 09:10:26 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317)

Philippe Torche wrote:
> The following script use eval with 3 pipes, 1st time with direct pipe on
> the command line, and the 2nd time with a pipe in a variable.
> In this second eval, the PIPESTATUS does not content 3 entries, but only 2.
> 
> cat <<'EOF' > eval_pipe.sh
> #!/bin/env bash
> set -u
> 
> eval echo 'titi' | grep toto | grep titi
> ret_codes=(${PIPESTATUS[*]})
> echo ret_codes=${ret_codes[*]}
> aPipe='|'
> eval echo 'titi' $aPipe grep toto | grep titi
> ret_codes=(${PIPESTATUS[*]})

I'd argue that this is, in fact, a two-element pipeline:

`eval echo 'titi' $aPipe grep toto' and `grep titi'.

When this completes, PIPESTATUS should contain two elements, as you
found.

The first command will eventually decompose into an additional two-stage
pipeline, which will set PIPESTATUS itself.  That setting will happen in
a subshell, and would subsequently be overwritten anyway.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@case.edu    http://tiswww.tis.case.edu/~chet/




reply via email to

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