Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have several utility programs that I need to run. What I am doing write now is going to the bin directory of thee apps and running .\program.sh to run them. Obviously not practical to run it everywhere this way. Putting the bin directory on my path would still not allow these scripts to be executed anywhere would it? So how should a .sh file be run from another directory?

share|improve this question
    
You need to adjust the PATH environment variable‌​. –  Oliver Salzburg May 10 '12 at 23:50
add comment

1 Answer 1

up vote 1 down vote accepted

Open the Terminal and edit the .bash_profile

You can add:

export PATH=<path to script folder(s)>:$PATH

Now run

. ~/.bash_profile

to update your terminal, then try:

which <scriptname>

If you see your script, all should be good!

share|improve this answer
    
but how would I then run the scripts? program.sh ./program.sh –  Code Droid May 11 '12 at 1:17
    
How would I execute the script? –  Code Droid May 11 '12 at 1:18
    
<scriptname> from the Terminal. Just use the name, and if you're not sure, it should have tab completion. –  MaddHacker May 11 '12 at 1:20
    
Oh I see. Just retrace.sh should now run it. –  Code Droid May 11 '12 at 1:21
1  
Yup, hope that helped! Keep in mind that the PATH is order dependent to, so when you run a command, it will look for the command in the folder in the order specified by the PATH environment variable (to view just run echo $PATH), meaning if you have 2 commands with the same name, the PATH order will determine which is run. –  MaddHacker May 11 '12 at 1:31
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.