views:

275

answers:

3

Hello

I have a shell script file (run.sh) that contains the following:

#!/bin/bash
%JAVA_HOME%/bin/java -jar umar.jar

when i try to run it (./run.sh), it gives me following: umar/bin/run.sh: line 1: fg: no job control

However if I run same command directly on shell, it works perfectly.

What's wrong with the script file?

Thanks

+2  A: 

Try turning on monitor mode

set -m
Shankar Ramachandran
+8  A: 

%foo% is not how you do command substitution in a bourne/BASH shell script. I assume you're running this from a Windows command line, which is why it works when you run it directly. Try using proper bourne syntax:

${JAVA_HOME}/bin/java -jar umar.jar
Paul Tomblin
Don't forget to protect the variable against spaces: `"$JAVA_HOME"/bin/java`.
Andrey Vlasovskikh
Thank Paul. I made the changes suggested by you. Atleast now I am not getting the "fg: no job control" message. But now it is giving me this error: "Unable to access jarfile umar.jar" even I have set all permissions true: "chmod 777 umar.jar".Strange fact is that it works perfectly if I run the jar directly from shell.
craftsman
Is umar.jar in the current directory?
Paul Tomblin
yes it is in current directory... This issue is also resolved by giving full path of jar file ... Now strangely I am getting a third type of error: "Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file"I guess I should start a new thread for this.
craftsman
Umar, that message is usually because it was compiled with a later version of the JDK than your JRE.
paxdiablo
But if it is so, then why the jar runs from command line but not from the script file?
craftsman
Considering that you are switching between Windows command shell and (probably cygwin?) bash, I'm guessing you have different PATH and CLASSPATH environments set, and therefore different java versions in play.
Paul Tomblin
@Paul, are we sure that Windows is involved here at all? Other than the %% markers in the file, I see no indication of this (and the question is tagged linux rather than Cygwin).
paxdiablo
He said that it worked with the %JAVA_HOME% from the command line. That would only be true if it was Windows.
Paul Tomblin
+2  A: 

%JAVA_HOME% will substitute a Windows environment variable and is appropriate in a .bat file.

Try the following shell script which should work on most UNIX like systems.

#!/bin/bash
$JAVA_HOME/bin/java -jar umar.jar
Russ