LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 11-11-2003, 02:17 PM   #1
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Rep: Reputation: 15
Question how do i edit my echo$PATH


How do I edit my echo$PATH?

Code:
pathmunge () {
	if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
	   if [ "$2" = "after" ] ; then
	      PATH=$PATH:$1
	   else
	      PATH=$1:$PATH
	   fi
	fi
}
I entered this code in my /etc/profile. I read that I was supposed to enter after PATH= what other location i wanted in my path. then i changed the code to

Code:
pathmunge () {
	if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
	   if [ "$2" = "after" ] ; then
	      PATH=$PATH:$1:/home/user1/  **change here, home user1 was added**
	   else
	      PATH=$1:$PATH
	   fi
	fi
}
how can i add this location to my PATH?
 
Old 11-11-2003, 02:28 PM   #2
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
That's pretty much what you did. Do a source /etc/profile.
But heads up! You shouldn't be entering a user's directory in /etc/profile. Even if you're the only one using the computer it's considered a bad habit. Also, you shouldn't have executables in your home directory. Create a bin directory in your home directory and edit your ~/.bashrc. If you have any PATH statements there you can use those, if not, type this in your .bashrc:
Code:
PATH=$PATH:/home/user1/bin
export PATH
Also, check your ~/.bash_profile to see if .bashrc is called there. If not, add this:
Code:
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi
This will make sure you always have your specialized path loaded (as long as you use bash as your default shell but you most likely do).

Then pop your executables in ~/bin and you can execute them from anywhere on your system.

Håkan
 
Old 11-11-2003, 02:32 PM   #3
Faecal
Member
 
Registered: Sep 2002
Location: York, UK
Distribution: Debian Sid
Posts: 215

Rep: Reputation: 30
What you have there is a function that takes an argument ($1) of a path to add to the PATH environment variable. First it looks to see if $1 is already in the path, and if it's not then it adds it to PATH: either at the front or end of the list, depending on whether a second argument of "after" was given. To do anything with this, you'd need to separate it off into a script file and call that from profile.

For most simple situations, it is sufficient to have a line such as
Code:
export PATH=$PATH:/my/added/path/
.

In your case, it appears that you are adding a user's home directory to the path. Since this will only be accessible to the user in question, it would be far wiser to set this change to PATH for the user alone. This may be done by editing /home/user1/.bash_profile instead of /etc/profile.

For instance:
Code:
jcspray@slate:~$ cat ~/.bash_profile 
PATH=$PATH:~/bin
That adds the directory /home/jcspray/bin/ to the PATH of the user jcspray. A pretty common approach.

Last edited by Faecal; 11-11-2003 at 02:33 PM.
 
Old 11-14-2003, 10:15 PM   #4
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Original Poster
Rep: Reputation: 15
ok i get it.. i had to restart the X system and it magically worked, w/e..

Also, could I just take all the scripts and put them in /usr/local/bin/ and edit the PATH again to look for "exe's" in the /usr/local/bin/ folder so that the PATH file could look neater, would this cause problems?

[code[
[gabriel@localhost gabriel]$ echo$PATH
bash: echo/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/govtspyagent30/Mozilla/: No such file or directory
[/code]


Last edited by Laptop2250; 11-14-2003 at 10:42 PM.
 
Old 11-15-2003, 08:03 AM   #5
Faecal
Member
 
Registered: Sep 2002
Location: York, UK
Distribution: Debian Sid
Posts: 215

Rep: Reputation: 30
>all the scripts and put them in /usr/local/bin/

I assume that you mean scripts which you've currently got in ~/bin? Certainly you could just stick them all in /usr/local/bin, but that's not necessarily a good idea. If it's something that all users on the system would find useful then fine, but there's not a lot of point going root and writing outside of your home directory just to make your $PATH variable shorter - I mean, how often do you look at it? Also, as you've posted it the reason it looks so ugly is that your command is malformed. "echo $PATH" is correct, "echo$PATH" is not.

>edit the PATH again to look for "exe's" in the /usr/local/bin/ folder
Doesn't look like it would need any editing - /usr/local/bin is already on there at the start if you notice. /usr/local/bin comes first, by the way, so that you can have a /usr/bin/myprogram and then create a /usr/local/bin/myprogram which overrides it.

>look for "exe's"
Bash never looks at non-executable files in $PATH, for obvious reasons.
 
Old 11-15-2003, 10:37 AM   #6
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Original Poster
Rep: Reputation: 15
echo $PATH does make it look neater, but the other reason I wanted to put everything in one folder in the PATH is because that way I know where the exe is, and I wouldn't have to guess which folder it is in (or search for it). But if I collected all the exe's from my current PATH and placed them in one random folder (whichever folder would make placing them there the most problem free) wouldn't that work? Or if I were to log on as root, would I have problems accessing anything? I'm a so I am just trying to figure out the easiest way to keep track of my files, folders, etc.
 
Old 11-15-2003, 12:33 PM   #7
Faecal
Member
 
Registered: Sep 2002
Location: York, UK
Distribution: Debian Sid
Posts: 215

Rep: Reputation: 30
Anything you put in /usr/local/bin is going to get shuffled in with any random programs that you install from source. The best way to keep track of anything is not to let it wander out of your home directory.

>if I collected all the exe's from my current PATH
Are you serious? You mean taking everything from /usr/bin, /usr/local/bin, /bin and putting it all in one directory? That's nuts. Where something is tells you something about it - things in /bin are pretty system-level, things in /usr/bin came from your distro's packaging system, things in /usr/local/bin came from source installations (generally). Just what kind of situation are you thinking of where it would be advantageous to have every binary on the system in one folder?

As for knowing where a given binary is, "whereis" and "locate" are you friends. But situations in which you'll care are rareish.

>I were to log on as root, would I have problems accessing anything
No, that's the whole point of being root :-) But seriously, anything in ~/bin is generally just a convenience of some kind. I mean, what kind of stuff is it that you're worrying about where to keep?
 
  


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
echo $PATH? blackzone Linux - Newbie 2 01-12-2005 11:58 PM
edit value of PATH permanently rsumbeling Linux - General 2 12-13-2004 11:57 AM
How do I edit my path? Echo Kilo Linux - General 3 12-12-2004 02:50 PM
echo $PATH problem acbenny Linux - General 15 08-12-2004 06:15 PM
How to edit the value of $PATH? ICO Slackware 1 02-07-2004 05:38 AM


All times are GMT -5. The time now is 06:01 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