Hi, Please cc me ‹ I¹m not subscribed to this list.
I have a script that works correctly in Bash 4.2.25(1)-release from Ubuntu 12.04 (package version 4.2-2ubuntu2) but that fails in Bash 4.3.0(1)-release from Ubuntu 14.04 prerelease (package version 4.3-2ubuntu1). The root of the problem is that I am using declare a inside a script that is sourced. In 4.2 this variable is still available in the outer scope. In 4.3 it is not, and I get an error when I try to use it. I haven¹t checked whether this is specific to array variables or whether it applies to other uses of declare too. Is this a known issue? It¹s not mentioned in COMPAT or the FAQ that I could find. All help appreciated! Thanks, Ewan. deploy.sh: #!/bin/bash set -eu . /usr/lib/tipbit/git_management.sh update_repo "/srv" www.tipbit.com www.tipbit.com production >/dev/null /usr/lib/tipbit/git_management.sh: update_repo() { (repo_parent_dir="$1" repo_dest_name="$2" repo_source_name="$3" branch="$4" repo_dest_dir="$repo_parent_dir/$repo_dest_name" . /usr/lib/tipbit/on_exit.sh eval $(ssh-agent) >/dev/null printf 'notasecret\n' | monkeysphere subkey-to-ssh-agent >/dev/null 2>&1 add_on_exit "kill $SSH_AGENT_PID² # Script proceeds... ) } /usr/lib/tipbit/on_exit.sh: #!/bin/bash declare -a on_exit_hooks on_exit() { for i in $(seq $((${#on_exit_hooks[*]} - 1)) -1 0) do eval "${on_exit_hooks[$i]}" done } add_on_exit() { local n=${#on_exit_hooks[*]} on_exit_hooks[$n]="$*" if [[ $n -eq 0 ]] then trap on_exit EXIT fi } Trace from Bash 4.3: $ bash -x ./deploy-tipbit.com.sh + set -eu + . /usr/lib/tipbit/git_management.sh + update_repo /srv www.tipbit.com www.tipbit.com production + repo_parent_dir=/srv + repo_dest_name=www.tipbit.com + repo_source_name=www.tipbit.com + branch=production + repo_dest_dir=/srv/www.tipbit.com + . /usr/lib/tipbit/on_exit.sh ++ declare -a on_exit_hooks ++ ssh-agent + eval 'SSH_AUTH_SOCK=/tmp/ssh-EQr2YBnPE5K7/agent.9147;' export 'SSH_AUTH_SOCK;' 'SSH_AGENT_PID=9148;' export 'SSH_AGENT_PID;' echo Agent pid '9148;' ++ SSH_AUTH_SOCK=/tmp/ssh-EQr2YBnPE5K7/agent.9147 ++ export SSH_AUTH_SOCK ++ SSH_AGENT_PID=9148 ++ export SSH_AGENT_PID ++ echo Agent pid 9148 + monkeysphere subkey-to-ssh-agent + printf 'notasecret\n' + add_on_exit 'kill 9148' /usr/lib/tipbit/on_exit.sh: line 19: on_exit_hooks: unbound variable Trace from Bash 4.2: $ bash -x ./deploy-tipbit.com.sh + set -eu + . /usr/lib/tipbit/git_management.sh + update_repo /srv www.tipbit.com www.tipbit.com production + repo_parent_dir=/srv + repo_dest_name=www.tipbit.com + repo_source_name=www.tipbit.com + branch=production + repo_dest_dir=/srv/www.tipbit.com + . /usr/lib/tipbit/on_exit.sh ++ declare -a on_exit_hooks ++ ssh-agent + eval 'SSH_AUTH_SOCK=/tmp/ssh-QrkegAwJO322/agent.322;' export 'SSH_AUTH_SOCK;' 'SSH_AGENT_PID=323;' export 'SSH_AGENT_PID;' echo Agent pid '323;' ++ SSH_AUTH_SOCK=/tmp/ssh-QrkegAwJO322/agent.322 ++ export SSH_AUTH_SOCK ++ SSH_AGENT_PID=323 ++ export SSH_AGENT_PID ++ echo Agent pid 323 + monkeysphere subkey-to-ssh-agent + printf 'notasecret\n' + add_on_exit 'kill 323' + local n=0 + on_exit_hooks[$n]='kill 323' + [[ 0 -eq 0 ]] + trap on_exit EXIT # Script proceeds...