1

I'm trying to add set -eu option in my script but it's throwing an error "Unbound variable error"

ssh -q $username@$server << EOF                            
set -eu    
echo "proceeding diagnostics"    
cd $CT_PATH    
bundle exec cap -q -S instance=$instance demo deploy:all;    
echo "completed process"
EOF

I would need to add -eu option on the script because -u option can catch non-existent variables.

Appreciate for you quick help on this

5
  • where are you setting values for CT_PATH and instance? If you're expecting they will be inherited from the environment on $server, then you need to use <<'EOF', and that's assuming those vars as set with export in some basic .rc file that is sourced by ssh . Good luck. Commented Aug 11, 2017 at 3:55
  • I'm calling CT_PATH from a separate script and instance name is passing from the input parameters Commented Aug 11, 2017 at 6:05
  • Since the only variables in your script are CT_PATH and instance, and it is unlikely that bundle will raise this error message, my guess is that one of these variables are not defined. I suggest that you output their values right before the set -eu, for instance like this: echo ${CT_PATH:-undefined} , ${instance:-undefined}. Commented Aug 11, 2017 at 6:48
  • "Calling from a separate script". Do you mean source mySepScript (or . mySepScript), because you must "source" a script for its vars to be visible inside a parent script. If you don't know what I mean search here for [bash] source. Good luck. Commented Aug 11, 2017 at 12:29
  • There was no issue with bundle but the problem is that we are unable to add set -eu option in the script. i'm calling the script source myscript.sh in the script. still i'm facing unbound variable. Can someone please help me out on this? Commented Aug 18, 2017 at 4:10

1 Answer 1

1

I recently ran into this, too. You need to initialize all variables before set -eu

My issue was this:

...
set -eu

for filename in folder/*.txt; do
    ... stuff ...
done

This threw the unbound variable issue. However, if I defined filename above set -eu to an empty string, the issue disappeared.

For your case, it seems like you need to initialize CT_PATH or instance before set -eu

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.