Adding PATH in Linux

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
I am running some scripts under BASH, but it seems my work DIR (/source) isn't listed in the PATH. I would
have to type ./example.sh in order to execute the script. How do I add directories to my PATH?
 

LNXman

Senior member
Jul 27, 2000
404
0
0
########Answer in Pseudo code mode#########

got to your home directory (i.e. cd ~).

if (you are using bash, sh or korn){
  1. -edit or create a .profile
  1. -add the following line export PATH=$PATH:<your_added_path>
}
else { #if you are using csh, or tcsh
  1. -edit or create a .cshrc
  1. -add the following line setenv PATH "$PATH:<your_added_path>"
}

REMINDER:
Make sure that you don't create a shell script name that already exists on the system, otherwise you will be executing the first one it finds from the PATH, and it might not be the one you want to execute.
 

Damaged

Diamond Member
Oct 11, 1999
3,020
0
0


<< REMINDER:
Make sure that you don't create a shell script name that already exists on the system, otherwise you will be executing the first one it finds from the PATH, and it might not be the one you want to execute.
>>


Actually you can get away with that, not that I recommend it. The $PATH will look in each directory in the order that they're in. So, if you put /home/<user>/bin first, it will look, and execute, anything in that directory first.