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.shIs 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 1 3 Answers
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 PATHI 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.
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
fiIf you want them to be available for all users, add them to /usr/local/bin
another solution
Add path to
~/.bashrcopen using vim$ vim ~/.bashrcexample:
# add extra paths export PATH=$PATH:~/Scriptsonce path is added run:
$ source ~/.bashrcIf added correctly there should be no errors.