LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-28-2013, 10:25 AM   #1
linuxkid12
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
PATH variable


Would it be wrong if the path variable was set like:

PATH=$HOME:$PATH

??

Would this be an infinite loop?

Should it be- PATH=$PATH:$HOME instead?
 
Old 05-28-2013, 10:51 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Not sure why you think it would be an infinite loop? Each variable only has a set amount of values and is evaluated exactly once. This is in turn assigned to what is on the LHS of the equation.

As for should you include your HOME path in your PATH variable I would consider the fact that of all the places where it is easiest for malicious commands to reside would be in a user directory,
I would not personally place it in the PATH at all.

As with all versions of linux though, the choice is completely yours
 
Old 05-28-2013, 11:34 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Quote:
Originally Posted by linuxkid12 View Post
Would it be wrong if the path variable was set like:

PATH=$HOME:$PATH

...

Should it be- PATH=$PATH:$HOME instead?
The only difference between these is what order the shell will search through your directories to find a match for whatever you typed. It will only make a difference if you have two programs with the same name, one in $HOME, and one elsewhere in $PATH, in which case the order will determine which one is selected.
 
Old 05-28-2013, 11:46 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
To answer your question, no it is not recursive.

The reason it is not recursive is due to the way shells interpret command lines.

1. expand all substitutions.
2. execute the command...

So if PATH had the value "/usr/bin" at the beginning, the first step would turn your command line:

PATH=$HOME:$PATH

into

PATH=/home/<username>:/usr/bin

Then it would do the assignment giving PATH the value "/home/<username>:/usr/bin"
 
  


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 variable ananthkadalur Linux - Newbie 7 08-03-2011 08:38 AM
Add path to $PATH variable alaios SUSE / openSUSE 2 04-19-2009 09:41 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
PATH variable jk21 Linux - Newbie 1 09-28-2004 03:48 PM
the path variable mjkramer Linux - Newbie 4 10-18-2003 08:18 AM


All times are GMT -5. The time now is 06:53 PM.

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