Having the following script test1.sh I'm wondering what is the reason of not getting the full list of declared variables with declare -p. For BASH_COMMAND surprisingly I'm not seeing the value but only declare -- BASH_COMMAND. After the variable is used then declare -p returns it properly.
What is the reason behind? What am I missing? I couldn't find the meaning of the declare -- also. What can I do to see all the variables for debug purpose?
#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset -o posix -o errtrace -o functrace -o hashall
# -o xtrace
function trapExit() {
#here we get the INCORECT declare with BASH_COMMAND having no value
declare -p | grep BASH_COMMAND
declare -p | grep BASH_COMMAND
value=$BASH_COMMAND
#here we get the CORRECT declare with BASH_COMMAND having the value
declare -p | grep BASH_COMMAND
echo "valueOfCommand=$value"
}
function test2() {
${MISSING_PARAM?"Parameter is missing in function test2"}
}
trap trapExit exit
test2
: <<END_COMMENT
$ ./test1.sh
./test1.sh: line 15: MISSING_PARAM: Parameter is missing in function test2
declare -- BASH_COMMAND
declare -- BASH_COMMAND="\${MISSING_PARAM?\"Parameter is missing in function test2\"}"
valueOfCommand=${MISSING_PARAM?"Parameter is missing in function test2"}
END_COMMENT