[Top][All Lists]

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

Re: [BUG] ERR trap triggered twice when using 'command'

From: Nick Chambers
Subject: Re: [BUG] ERR trap triggered twice when using 'command'
Date: Mon, 2 Apr 2018 14:48:55 +0000

On 4/1/18, 5:54 AM, "bug-bash on behalf of Martijn Dekker" <address@hidden on 
behalf of address@hidden> wrote:

    $ bash -c 'trap "echo WHOA" ERR; command false'
    Expected output: just one WHOA (as on *ksh, zsh)
    - M.
While you should still use the bashbug tool, I’m not sure if this is actually a 
bug. If you consider the following:

NickChambers-iMac:~ Nick$ type command
command is a shell builtin

This means that when you execute `command false`, false is executed in a child 
subshell and command is executed in the current shell, and both return 1. Bash 
is able to see the exit status of false (since command is just a glorified C 
function in this case), so it activates the ERR trap. Then command exits, and 
bash once again activates the ERR trap (since command has the same exit status 
as the command it executed). If you execute `command false` in a subshell, bash 
will only see the exit status of command:

NickChambers-iMac:~ Nick$ trap 'echo WHOA' ERR
NickChambers-iMac:~ Nick$ ( command false )
NickChambers-iMac:~ Nick$

reply via email to

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