0

我正在尝试在新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实例中执行一组命令吗?

4

1 回答 1

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" | bash或_bash -c "$cmd"

于 2013-05-10T00:22:50.260 回答