Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an executable, called "octane", that I want to be able to launch globally. The executable requires access to a local binary, "octane.dat", in order to run.

I placed the directory containing the executable and the binary in /opt/ as root and created a symbolic link of the executable in /usr/local/bin/. Now, if I type "octane" anywhere, it launches but throws up an error saying it won't run without the binary, "octane.dat". Octane will only launch if my current working directory is the same as the executable and binary, in /usr/local/bin.

Any suggestions on how to fix this? Do I have to make that directory global using .bashrc?

Thanks.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Instead of the symbolic link you can create a wrapper script in /usr/local/bin:

#! /bin/sh
cd /opt/octane
exec ./octane "$@"

Make the script executable with chmod +x /usr/local/bin/octane.

The "$@" are the command line arguments, so you can still run octane an_argument.

The script changes the CWD (current working directory) only inside the script, because the script is run in a whole new shell instance which ends at the end of the script. Changing the current working directory for the executable might actually be a problem if you want to give a relative pathname to the executable. E.g. if you are in your home directory and run octane a_file_in_the_home_directory, it doesn't work, because the octane executable is called with a CWD of /opt/octane, and a_file_in_the_home_directory is not in /opt/octane. If that is a concern, you can either remember to give absolute pathnames only (octane ~/a_file_in_the_home_directory) or use a more complicated version of the script.

share|improve this answer
    
That worked perfectly. Thanks! I'm glad it doesn't change the CWD. I thought it would...is that what the "$@" is for? –  kedmond Dec 19 '12 at 18:43
1  
Glad it worked; I updated my answer with the answer to your comment. –  elmicha Dec 20 '12 at 23:24
    
You rock, thanks! –  kedmond Dec 21 '12 at 18:09
add comment

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.