0

I'm trying execute a set of commands in a new bash session:

exec bash <<- EOF
   ln -snf $JDK_REPO'/jdk'$1 $CURRENT;
   JAVA_HOME=$(readlink -f $CURRENT);
   echo $JAVA_HOME;
   export PATH= $JAVA_HOME/bin:$PATH;
   exec usejdk 
   EOF

I get this error :

 warning: here-document at line 46 delimited by end-of-file (wanted `EOF')

I tried to debug it with whatswrongwithmyscript, I get :

Use <<- instead of << if you want to indent the end token.

Any suggestion to execute a set of commands in a new bash instance ?

2
  • 1
    Like a Makefile, you must indent with tab chars. see gnu.org/software/bash/manual/bashref.html#Here-Documents Commented May 10, 2013 at 0:29
  • Interesting, thanks @glennjackman , I will try it with the herdoc approach again to make sure that I'm not doing white-spaces killer mistakes. Commented May 10, 2013 at 0:32

1 Answer 1

2

doing it this way works for me:

cmd="
   ln -snf $JDK_REPO'/jdk'$1 $CURRENT;
   JAVA_HOME=$(readlink -f $CURRENT);
   echo $JAVA_HOME;
   export PATH= $JAVA_HOME/bin:$PATH;
   exec usejdk"
bash <<< "$cmd"

The bash <<< "$cmd" is equivalent to echo "$cmd" | bash or bash -c "$cmd"

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

3 Comments

Thanks @Lynch , I see <<< for the first time, white-spaces are killing me when writing bash scripts, first steps :)
Taking the habit to always quotes your variables is a good thing. otherwise strange things happen.
strange things always happen with bash.

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.