aws-codedeploy-agent icon indicating copy to clipboard operation
aws-codedeploy-agent copied to clipboard

Getting an "unbound variable" error in Bash scripts

Open rnhurt opened this issue 5 years ago • 3 comments

I'm getting a weird 'unbound variable' problem when I try to run my AfterInstall script. This same script works fine in Amazon Linux1 under the same environment (Ruby / RVM).

Environment:

  • Amazon Linux2
  • Ruby 2.5.8 (RVM)
  • Latest CodeDeploy agent

This is the first part of my config/code_deploy/after_install.sh script. It seems to be choking on the cd command for some reason.

#!/bin/bash
set -euxo pipefail
export RAILS_ENV=$DEPLOYMENT_GROUP_NAME
cd /var/site/current
...

This is the error that I'm getting in CodeDeploy. I have no idea what 'unbound variable' it's trying to find.

LifecycleEvent - AfterInstall
Script - config/code_deploy/after_install.sh
[stderr]+ export RAILS_ENV=myenv
[stderr]+ RAILS_ENV=myenv
[stderr]+ cd /var/site/current
[stderr]+ __zsh_like_cd cd /var/site/current
[stderr]+ typeset __zsh_like_cd_hook
[stderr]+ builtin cd /var/site/current
[stderr]/opt/codedeploy-agent/deployment-root/5f156457-724d-48f6-8105-222222222222/d-11111111/deployment-archive/config/code_deploy/after_install.sh: chpwd_functions[@]: unbound variable

rnhurt avatar Nov 11 '20 15:11 rnhurt

Try printing the variables in your script or set default values for them? Something appears to be unbound https://unix.stackexchange.com/questions/463034/bash-throws-error-line-8-1-unbound-variable

philstrong avatar Jan 26 '21 15:01 philstrong

I'm getting this issue as well - did you have any luck fixing it?

kieraneglin avatar Jul 20 '21 17:07 kieraneglin

I'm very sorry. I don't remember how/if I fixed this. I think it was related to RVM in some way, but I really don't know. :disappointed:

rnhurt avatar Jul 20 '21 18:07 rnhurt