In a bash shell script I tried these two versions:
java -jar abc.jar&
and
CMD="java -jar abc.jar&"
$CMD
The first verison works, and the second version complains that abc.jar cannot be found. Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Commands do run from current directory in a shell script.
This is why the first command in your test script worked.
The second command may not work because either
javaisn’t in your${PATH}orabc.jarisn’t in your${CLASSPATH}. You couldechothese environment variables orset +xto debug yourbashscript.