LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 09: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, 09:51 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
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, 10:34 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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, 10:46 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 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
Open Source Consulting | Domain Registration