Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to launch a program through a variable and it reads run.sh fine but it runs into issues when trying to launch the .jar file.

Normal running run.sh works fine and it launches the program as you can see below.

What is the problem?

:~$ HAVEN=Desktop/Haven/run.sh
:~$ echo $HAVEN
Desktop/Haven/run.sh
:~$ $HAVEN
Error: Unable to access jarfile hafen.jar
:~$ cd Desktop/Haven
:~/Desktop/Haven$ ./run.sh
:~/Desktop/Haven$ 
share|improve this question
    
Can you edit your question to include the script, run.sh? – Greenonline Mar 29 at 9:22
up vote 4 down vote accepted

Sounds like run.sh is using relative paths. Your current working directory when you run it from ~/ is ~/ not ~/Desktop/Haven.

You can fix this by cding to the directory of the script somewhere near the beginning of run.sh, with something like this:

cd "$(dirname "$(readlink -f -- "$0")")"

That, or you could have it specify the full paths to your jars.

share|improve this answer
    
Thanks. Your first sentence helped me fix the problem. I changed hafen.jar to Desktop/Haven/hafen.jar – Johnny Louweret Mar 29 at 9:24

In case any variable is not working you can specify binary path of the command.

like.. If you use cp command and it does not work you can mention /bin/cp (Binary file for this command). In the same fashion you can use in you case as per the requirement.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.