I’m on a Mac OS X 10.8.2
I have a simple bash script executing a jar file (a simple hello world gui program with a window)
#!/bin/sh
if ls /Applications/javahello.jar >& /dev/null ; then
echo "File exists."
java -jar /Applications/javahello.jar
exit 0
else
echo "File doesn't exist."
exit 1
fi
The problem is that the script executes the jar, a window pops up and the terminal window stays “occupied” with a File Exists message. it never finishes its execution. …until I manually terminate the java program more precisely
I need to be able to execute the java program in this bash script in such a way that the script exits without waiting for the java program to finish running.
This would occur at the end of a installer package that copies the jar file into /Applications/ folder … as is, the installer never finishes and is obviously waiting for shell script to finish its execution.
Just put the
javaprocess in the background with&.Also, you don’t need
lsto tell if a file exists:Also also, since you’re using the filename twice, if you edit the script to change the filename or make a copy to run a different jar file or whatever, you might make a typo where the two filenames differ. A shell parameter will fix that so it can’t happen: