LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   symlinking with source directory structure (https://www.linuxquestions.org/questions/linux-newbie-8/symlinking-with-source-directory-structure-4175444220/)

devnull10 01-04-2013 07:39 PM

symlinking with source directory structure
 
Hi,
I have downloaded a utility which I have put in /opt. Now, rather than put /opt/myutil/bin/ in my PATH, I prefer to symlink from /usr/local/bin/myutility.
The only problem I get is that the utility looks for files relative to where it has been launched from, so in this case it is /usr/local/bin rather than /opt/myutil/bin.

Is there any way I can get the symlink to look as though it has been launched from the source rather than the target?

shivaa 01-04-2013 10:40 PM

You can store the utility in /usr/local/bin/ (source directory) and then create a symlink of it in /opt/myutil/bin (i.e. target directory) OR in your home directory, like this:
Code:

cd /opt/myutil/bin
ln -s /usr/local/bin/myutility myutility

OR To add a symlink in home dir:
Code:

cd /home/username
ln -s /usr/local/bin/myutility myutility

Then, in /opt/myutil/bin or /home/username, using ls -l you will see something like:-
Code:

...... myutility -> /usr/local/bin/myutility
And you can then invoke myutility while residing in /opt/myutil/bin or in /home/username dir. and you won't need to add any dir. to your PATH variable.

NevemTeve 01-05-2013 10:25 AM

Your utility might have an environment variable to control this (eg: ORACLE_HOME, JAVA_HOME, MOZILLA_HOME). Consult the manual. If it is so, create a script like this:

Code:

$ cat /usr/local/bin/myutil
#!/bin/sh
export MYUTIL_HOME='/opt/myutil'
exec "$MYUTIL_HOME/bin/myutility"



All times are GMT -5. The time now is 02:09 PM.