1: #!/bin/sh 2: # Example 16 3: 4: # Uses ex13.sh to generate some output and give us an 5: # exit status to capture. 6: 7: # Get the exit status of ex13 into ex13stat. 8: # stderr of ex13 is processed by the pipe, stdout 9: # is left alone. 10: 11: # Save a copy of stdout 12: exec 3>&1 13: 14: # Run a subshell, with 4 copied to 1 so we get it in stdout. 15: # Capture the output in backtics` 16: # ex13stat=`( ) 4>&1` 17: 18: # In the subshell, run another subshell to execute ex13, and 19: # echo the status code to 4 20: # (./ex13.sh; echo $? >&4) 21: 22: # stdout from the inner subshell is directed to the original stdout (3) 23: # stderr is passed into the pipe for further processing. 24: # stdout from the pipe is redirected back to stderr 25: 26: # Close the extra descriptors before running the commands 27: exec 3>&1 28: ex13stat=`((./ex13.sh 2>&1 1>&3 3>&- 4>&- ; echo $? >&4) | \ 29: sed s/err/ERR/ 1>&2 3>&- 4>&- ) 4>&1` 30: 31: echo Last command status=$? 32: echo ex13stat=$ex13stat 33:
| last modified 02/04/2009 | Introduction | Table of Contents (frame/no frame) |
Printable (single file) |
© Dartmouth College |