简体   繁体   中英

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

This command works great from terminal $java -jar $picard

Whenever I put that in bash script, It gives error as: line 2: -jar: command not found

#!/bin/sh
$java -jar $picard`

Is there any fix, thanks?

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/sh
java -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 java
export 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM