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 some bash scripts in an application folder that I'd like to use as if they were on my path. If they were straight-up applications, I'd just add the directory to ~/.bashrc, but these are scripts.

eg:

~/a_dir/another_dir/foo.sh
~/a_dir/another_dir/foo-gui.sh

Is there a good way to set up a path so that I can use them from any directory?

eg:

totally/different/path$ bash foo.sh
share|improve this question
    
you won't be able to do it with bash foo.sh, but with foo.sh, after giving exec permission and putting them in the $PATH. –  elias Jan 23 '12 at 20:15

3 Answers 3

up vote 6 down vote accepted

Yes, you can add any directory to the system path. One way to do this is updating the PATH (environmental variable) definition. You can do this in your .bashrc by adding the following lines:

PATH="/your/script/dir:${PATH}"
export PATH

I like to add my scripts to $HOME/.local/bin/ (which is a hidden directory) so my home dir stays cleaner.

Your directory will not get inserted into the PATH variable right away, unless you run source .bashrc.

You can add multiple directories to the path, remember that. Please consult BASH documentation if you do not understand the code.

The previous method will only work for your user. If you need to add a script directory for all users do as bodhi.zazen and add your scripts to /usr/local/bin.

share|improve this answer

IMO the best method is to add the scripts to ~/bin

mkdir ~/bin

~/bin should automatically be added to your path. If not, add this to ~/.bashrc

if [ -d $HOME/bin ]; then
    PATH=$PATH:$HOME/bin
fi

If you want them to be available for all users, add them to /usr/local/bin

share|improve this answer
    
In this case, since it's scripts from an applications, I'd advise to put symbolic links for the scripts in the ~/bin, for better maintainability. –  elias Jan 23 '12 at 20:13

another solution

  1. Add path to ~/.bashrc open using vim $ vim ~/.bashrc

    example:

    # add extra paths export PATH=$PATH:~/Scripts

  2. once path is added run:

    $ source ~/.bashrc

  3. If added correctly there should be no errors.

share|improve this answer

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.