LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   bash commands (https://www.linuxquestions.org/questions/slackware-14/bash-commands-310248/)

davatar 04-06-2005 02:39 AM

bash commands
 
I have a question reguarding executing files. Is it possible to execute a script from a different directory, making the script believe you are executing it from the directory it lives in?

For example, this is my situation:

I have Cube 3D on my box, but it is not a package or source to compile, it simply runs "as is" once extracted into a directory. The scripts obviously are written to use whatever path you're located at when you execute the main script. This gives me path errors when executing from a different directory, because the script is trying to find the necessary files in /whatever/directory/I'm/in/bin_unix/blah/blah instead of
/opt/cube/bin_unix, where it's all actually located.

Instead of editing all the scripts included with the game.. is there a way to make it appear as if the script was executed from it's root directory? (All of this, so that I may place a symlink to it in /usr/bin?)

~Davatar

theYinYeti 04-06-2005 02:54 AM

Yes, there's a way!
Code:

# cat >/usr/local/bin/myCube.sh <<-"THEEND"
#!/bin/bash
cd /opt/cube && ./cube
THEEND
# chmod 755 /usr/local/bin/myCube.sh

Now just use /usr/local/bin/myCube.sh, which should be in your PATH. HTH.

Yves.

davatar 04-06-2005 03:05 AM

Awesome! Thanks. =)


All times are GMT -5. The time now is 01:32 PM.