UNIX: java program command running from terminal but not working from bash script UNIX: java program command running from terminal but not working from bash script unix unix

UNIX: java program command running from terminal but not working from bash script


The $ at the beginning of the line is not part of the command; it is part of the shell prompt.

When you put the command in a batch file, you should not include the shell prompt. So change it to:

#!/bin/shjava -jar $picard

EDIT

OP mentioned that "$java" points to the actual Java binary.

If you are following naming conventions for shell scripts then $java and $picard are local variables in your shell, not environment variables, so they don't get passed onto any commands that you invoke.

To turn them into environment variables, you need to export them from your shell. Whereever you set values in them is the best place to put:

export javaexport picard

However, this turns them into environment variables, and in that case you should make the names "all capitals" -> JAVA, PICARD.


You have to export the java variable which you are using to point to java path as below

JAVA_CLASSPATH=/bin/jre1.8.0_101/bin/java

export PICARD_CLASSPATH=/bin/picard-tools-2.5.0/picard.jar

$JAVA_CLASSPATH -classpath $PICARD_CLASSPATH {Nmae of the Class from where the execution begins}

Instead of using small case you can use capital letter so it will be more readable.