Re: Bash: trap vs. tee
On 2008-07-13 17:59 +0200, Stefan Schmidt wrote:
> I have a bash script with trap, but the trap doesn't catch the error.
>
> function handle {
> echo "This should be reached
Closing quotes are missing, but your script hopefully has them.
> exit 1
> }
> trap handle ERR
> ls nonexist | tee -a output.log
> echo "This should not be reached"
>
> outputs
>
> ls: nonexist: No such file or directory
> This should not be reached
>
> How come?
Because the exit status of the pipe is that of the last command, and tee
has no reason to complain:
,----
| % ls nonexistent | tee -a output.log
| ls: cannot access nonexistent: No such file or directory
| % echo $?
| 0
| %
`----
In bash you can change this behavior with "set -o pipefail".
Sven
Reply to: