Add a directory to the execution PATH?

Need help with C, C++, perl, python, etc?

Add a directory to the execution PATH?

Postby dugb » 2007-05-08 00:54

Hi I am new to Linux and trying to learn. I want to add the following directory to the execution PATH.

/home/doug/code

I have tried this:

export PATH=$PATH:/home/doug/code

and it works until I exit, then I have to do it again. How can I set it up so I do not have to enter it every time I log in?

I would only like that directory for user doug. Could I also set up another directory that would be used by all users?

Thanks,
dugb
 
Posts: 27
Joined: 2007-05-02 12:39

Postby Telemachus » 2007-05-08 01:07

The easiest way I know of is to add the command you have been using to your .bashrc file. In your home directory, just open .bashrc (the . matters - it hides the file from normal view and it's part of the name of the file) with your favorite editor. Then add that line to the bottom of the file, and the next time you log in as Doug it should be there. Check with Google for tons and tons of good tutorials for Linux and for Bash. That's pretty much how I got started.
User avatar
Telemachus
 
Posts: 4677
Joined: 2006-12-25 15:53

Postby dugb » 2007-05-08 01:12

Ok that worked, thanks.
dugb
 
Posts: 27
Joined: 2007-05-02 12:39

Postby dugb » 2007-05-08 01:28

ok next question.

I want to set a directory for all users to use.

something like
/code

From google I learn that I need to set it up in /etc/profile

My question is should I place something like
export PATH=$PATH:/code in /etc/profile

or since these lines are there

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
fi

could I modify them to

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/code"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/code"
fi

Anyway, I will try it and see if it works if not I will be back to ask more questions.
dugb
 
Posts: 27
Joined: 2007-05-02 12:39

Postby Jackiebrown » 2007-05-08 01:36

The first path in the if statement is for the root user.
User avatar
Jackiebrown
 
Posts: 1276
Joined: 2007-01-02 04:46
Location: San Antonio, TX

Postby dugb » 2007-05-08 01:42

ok both ways I tried worked.

Jackiebrown: Thanks that was going to be my next question.
dugb
 
Posts: 27
Joined: 2007-05-02 12:39

Postby Telemachus » 2007-05-08 12:09

The root user always has a number of 0, and 'id -u' tests for the id number of the current user.
User avatar
Telemachus
 
Posts: 4677
Joined: 2006-12-25 15:53


Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable