Ubuntu – launching executable from /usr/local/bin needs access to local file

executablefilesinstallation

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.

Best Answer

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.

Related Question