LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-02-2013, 06:47 AM   #1
jack_bishop
LQ Newbie
 
Registered: Jul 2012
Posts: 1

Rep: Reputation: Disabled
$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?
 
Old 04-02-2013, 06:55 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
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.
 
Old 04-02-2013, 09:21 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.
 
Old 04-02-2013, 10:27 AM   #4
Ginola
Member
 
Registered: Sep 2012
Location: UK
Distribution: CentOS, RHEL
Posts: 70

Rep: Reputation: Disabled
FYI: An alias will be run before it looks in the PATH.
 
Old 04-02-2013, 04:45 PM   #5
Nbiser
Member
 
Registered: Oct 2012
Location: Maryland
Distribution: Fedora, Slackware, Debian, Ubuntu, Knoppix, Helix,
Posts: 302
Blog Entries: 7

Rep: Reputation: 44
Quote:
Originally Posted by jack_bishop View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PATH question. AsherSevyn Linux - Newbie 5 12-01-2012 01:20 PM
c++ - path question babag Programming 1 05-27-2008 03:27 AM
PATH question satimis Linux From Scratch 5 09-15-2005 10:23 AM
Another $PATH question iamnilo Fedora 2 09-13-2004 03:02 PM
Question on path PatC Linux - General 1 07-09-2002 09:17 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration