1

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, $java is a directory: /bin/jre1.8.0_101/bin/java and $picard is /bin/picard-tools-2.5.0/picard.jar
0

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.

2 Comments

One of the main features of the java -jar option is that you DON'T specify the name of main class in the command, instead it comes from the manifest in the jar. Also using the name JAVA_CLASSPATH for (a variable designating) a single executable file is very misleading and confusing to humans, although the shell doesn't care.
I assumed that picard is a library he is using to execute some Java class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.