It is currently Sat, 04 Dec 2021 18:29:15 GMT

Author Message
 bash: catch status of command before piping
In bash, we can check the variable $? to see the status of the last
command. Is there a way (besides saving to a file) to save the status
to a variable before it is overwritten? What I want to accomplish is

command1 save $? | command2 |command3

I have three commands in pipe and want to know the status of command1.
If I check $? after the entire line finishes executing, $? will reflect
the status of command3, not command1.

I would like to save the status of command1 to a variable, not a file,
and use it later in the same script. Anyway to do it? Thanks.

Sent via

 Mon, 21 Jul 2003 02:01:55 GMT   
 bash: catch status of command before piping

Check out the PIPESTATUS array variable.

``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    c...@po.CWRU.Edu

 Mon, 21 Jul 2003 03:22:02 GMT   
   [ 2 post ] 

Similar Threads

1. getting status from first command in a piped command line

2. Bash shell is always returning last exit status of the pipe

3. Obtaining the exit code (status) of command piped to tee

4. pipe but still grab command status

5. Difficulty retrieving exit status of command before pipe

6. Get exit status of first command in pipe.

7. Exit status of first command when using pipe

8. getting status from a subshell command in a pipe-line

9. How to negate command exit status in bash

10. Negating command exit status in bash

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software