从脚本中执行新bash实例中的一组命令

时间:2013-05-10 00:17:59

标签: linux bash shell unix heredoc

我正在尝试在新的bash会话中执行一组命令:

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

我收到错误

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

我尝试用whatswrongwithmyscript调试它,我得到:

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

是否有建议在 bash实例中执行一组命令?

1 个答案:

答案 0 :(得分:2)

这样做对我有用:

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"

bash <<< "$cmd"相当于echo "$cmd" | bashbash -c "$cmd"