Peng Yu
2018-12-05 06:51:13 UTC
Hi,
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?
BASH_COMMAND
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.
$ ./main.sh
declare -- BASH_COMMAND="( exit 1 )"
declare -- BASH_COMMAND="( exit 2 )"
declare -- BASH_COMMAND="[[ -n y ]]"
declare -- BASH_COMMAND="( exit 4 )"
$ cat ./main.sh
#!/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)
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?
BASH_COMMAND
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.
$ ./main.sh
declare -- BASH_COMMAND="( exit 1 )"
declare -- BASH_COMMAND="( exit 2 )"
declare -- BASH_COMMAND="[[ -n y ]]"
declare -- BASH_COMMAND="( exit 4 )"
$ cat ./main.sh
#!/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)
--
Regards,
Peng
Regards,
Peng