Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  24] [ 0]  / answers: 1 / hits: 62311  / 2 Years ago, sun, january 2, 2022, 11:12:21

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

More From » bash

 Answers
1

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.


[#40797] Tuesday, January 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ithriv

Total Points: 46
Total Questions: 115
Total Answers: 96

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;