I created two traps
trap function1 DEBUG
trap pwd ERR
function function1 {
echo $BASH_COMMAND
}
If I use some wrong command let's say a
, then output is->
a
bash: a: command not found
a
/home/user/dir
So second time DEBUG is called to execute pwd
, but why $BASH_COMMAND is still a? Is there any way to know in the function1 that this call to function is made while executing command in trap ERR
?
EDIT
Two traps are
trap -- 'f' DEBUG
trap -- 's' ERR
function f
{
echo "inside function f command is $BASH_COMMAND"
}
function s
{
echo "inside function s command is $BASH_COMMAND"
}
Output for wrong command a
, is
inside function f command is a
bash: a: command not found
inside function f command is a
inside function s command is echo "inside function s command is $BASH_COMMAND"
The second inside function f command is a
, must be from ERR trap.