Hi, "declare -g var" should return a nonzero return code when it fails.
Declaring a local variable as global in a function, has a exit status of 0, but the operation was not successful (see test_error). "help declare" and the bash man page indicate the exit status will indicate success or failure. The "declare -g var", did not just fail with a return code of 0, but it also removed the variable from the environment. Isn't that grounds for a nonzero return code... # Test Example # printf -- '%s ' "${BASH_VERSINFO[@]}" ; printf -- '\n\n' function test_success() { declare -g var ; echo "${FUNCNAME}: rc [$?]" var=data1 declare -p var } function test_error() { # Locally declared variable declare var="data2" ; echo "${FUNCNAME}: rc [$?]" declare -p var # Redeclare local variable as global # Why return code 0? # It apparently is not global. Nonexistent. declare -g var ; echo "${FUNCNAME}: rc [$?]" declare -p var # var=data3 declare -p var } test_success echo "== test_success: [$var]" echo; unset var declare -p var echo test_error echo "== test_error: [$var]" Output: =============================================== 4 2 42 1 release x86_64-suse-linux-gnu 1 test_success: rc [0] declare -- var="data1" == test_success: [data1] ./zt: line 28: declare: var: not found 2 test_error: rc [0] declare -- var="data2" 3 test_error: rc [0] <=== ./zt: line 18: declare: var: not found <=== declare -- var="data3" == test_error: [] =============================================== Peggy Russell