[Top][All Lists]

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

[Help-bash] Why should [[ reset BASH_COMMAND in trap?

From: Peng Yu
Subject: [Help-bash] Why should [[ reset BASH_COMMAND in trap?
Date: Wed, 5 Dec 2018 00:51:13 -0600


See the code below. [[ set BASH_COMMAND to [[ itself. But according to
the manual, should BASH_COMMAND remain as the command that causes the
trap (i.e., "(exit 3)", in this case). Do I misunderstand anything in
the manual or this is a bug of Bash?

              The command currently being executed or about to be
executed, unless the  shell
              is executing a command as the result of a trap, in which
case it is the command
              executing at the time of the trap.

$ ./
declare -- BASH_COMMAND="( exit 1 )"
declare -- BASH_COMMAND="( exit 2 )"
declare -- BASH_COMMAND="[[ -n y ]]"
declare -- BASH_COMMAND="( exit 4 )"
$ cat ./
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

trap 'true; declare -p BASH_COMMAND' ERR
(exit 1)
trap 'false; declare -p BASH_COMMAND' ERR
(exit 2)
trap '[[ x ]]; [[ y ]]; declare -p BASH_COMMAND' ERR
(exit 3)
trap '[ x ]; declare -p BASH_COMMAND' ERR
(exit 4)


reply via email to

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