不要命令,从当前目录中的shell脚本运行?
问题描述:
在一个bash shell脚本我试过这两个版本:
In a bash shell script I tried these two versions:
java -jar abc.jar&
和
CMD="java -jar abc.jar&"
$CMD
第一verison工作,以及所述第二版本抱怨abc.jar无法找到。为什么呢?
The first verison works, and the second version complains that abc.jar cannot be found. Why?
答
命令执行从一个shell脚本当前目录运行。
Commands do run from current directory in a shell script.
这就是为什么在你的测试脚本的第一个命令的工作。
This is why the first command in your test script worked.
第二个命令可能无法正常工作,因为无论的Java
是不是在你的 $ {PATH}
或 abc.jar
是不是在你的 $ {CLASSPATH}
。你可以回声
这些环境变量或设置+ X
来调试你的庆典
脚本。
The second command may not work because either java
isn't in your ${PATH}
or abc.jar
isn't in your ${CLASSPATH}
. You could echo
these environment variables or set +x
to debug your bash
script.