LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   $PATH question (https://www.linuxquestions.org/questions/linux-newbie-8/%24path-question-4175456495/)

jack_bishop 04-02-2013 06:47 AM

$PATH question
 
If you have two scripts with the same name in different directories in $PATH, which one runs?

For example, I have /usr/bin/myscript.sh and /usr/local/bin/myscript.sh.


Code:

user@linux>echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

When I run myscript.sh, only one will get executed, but which one? How can I change that?

eSelix 04-02-2013 06:55 AM

First is launched from "/usr/bin" because it is ealier in PATH variable than "/usr/local/bin". How to change depends on distribution. For example in Ubuntu you can edit PATH environment variable in file "/etc/environment" globally or in your home directory in ".profile" file for one user.

shivaa 04-02-2013 09:21 AM

It reads from left to right. So it will consider the one that comes first. i.e. if your script is in /usr/bin and /bin both, then it will consider the one which is in /usr/bin.

Ginola 04-02-2013 10:27 AM

FYI: An alias will be run before it looks in the PATH.

Nbiser 04-02-2013 04:45 PM

Quote:

Originally Posted by jack_bishop (Post 4923404)
If you have two scripts with the same name in different directories in $PATH, which one runs?

For example, I have /usr/bin/myscript.sh and /usr/local/bin/myscript.sh.


Code:

user@linux>echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

When I run myscript.sh, only one will get executed, but which one? How can I change that?

Which operating system are you using? This will help us tell you what command to use.

Cheers!
Nbiser


All times are GMT -5. The time now is 02:19 AM.