LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   adding variables to the PATH (https://www.linuxquestions.org/questions/linux-newbie-8/adding-variables-to-the-path-514688/)

myrto 12-29-2006 02:59 PM

adding variables to the PATH
 
I have recently downloaded ns-2 network simulator and I am trying to add ns' directory to the environment variable PATH. The path of the directory that contains a link to the ns's executable file is:
/home/Myrto/ns-allinone-2.30/bin
and the path of the actual executable file is:
/home/Myrto/ns-allinone-2.30/ns-2.30/ns

I have tried:
export ns=/home/Myrto/ns-allinone-2.30/bin
export $PATH=$PATH:$ns

along with just about anything else that I could think of but I always get the message 'not a valid identifier'.
If anyone could offer any suggestions I would be very grateful! Thanks.

dombrowsky 12-29-2006 03:09 PM

look at that code one more time.... carefully.

you're doing this:
Code:

A=foo
$A=$A:bar

which evaluates to
Code:

A=foo
foo=foo:bar

which may or may not work, and is certainly not what you intended.

voger 12-29-2006 03:26 PM

Code:

export PATH=$PATH:/home/Myrto/ns-allinone-2.30/bin

myrto 12-30-2006 12:53 AM

Thank you very much!

dv502 12-30-2006 11:36 PM

The code voger gave you is correct. But you have to run that command each time you boot up your computer or login. Linux reads the default PATH statement from your profile or login script.

If you use the bash shell. In your home directory, you will have either profile or bash_profile. There will be something like
this in either file:

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:."

The colons separate the folders. The period at the end of the PATH varible means you can run a program from the current directory. As an
example, put the directory you want betwwen
the coloons. Like this for example

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/home/Myrto/ns-allinone-2.30/bin:."

Save and exit. To take effect, you must log
out and then log in. Or you can type
source profile or source bash_profile. The
source command will re-read the file. Now you
can run the program anywhere from your home
directory.

Hope this helps you out.

hottdogg 01-21-2007 10:31 PM

How to add variable permanently (so I don't have to export everytime I login) without altering the current path variables if my .bash_profile and.bashrc are blank?
for example i want to add this: /usr/local/arm/bin

Currently I can only see the path variables using echo $PATH

tnx.

dv502 01-22-2007 01:06 AM

If your .bash_profile or .bashrc is blank, then you need
to edit the /etc/profile as root.

Open the /etc/profile with any text editor.

Search for something like this, yours may vary.

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:."

Each directory is separated by colons. Add the directory you want, in your case /usr/local/arm/bin within the colons. An example

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/usr/local/arm/bin:."

Save and exit. To take effect, you need to logout and then login.


Good luck

dombrowsky 01-22-2007 02:23 PM

Quote:

If your .bash_profile or .bashrc is blank, then you need
to edit the /etc/profile as root.
You shouldn't be doing this if you don't understand exactly what the files are and where they insert themselves in login/boot scripts.

For the details on what bash(1) runs on startup/login, see the INVOCATION section of the manual (type 'man bash'). In short, ~/.bash_profile is only run on login.

In almost all setups I've seen, there is a default .bash_profile that contains something like:
Code:

# include .bashrc if it exists

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

This means, all you have to do is CREATE the ~/.bashrc file and it will automagically be sourced in the login shell.

-dave

hottdogg 01-23-2007 08:34 PM

hmm..getting more confused:confused:
oh ..1 more thing I can also look path variables using 'set'.
Anyway, I'm newbie about this bash thing.
I've read the INVOCATION part in bash man.
actually, i want to make /usr/local/arm/bin behave like this :
user (either from gui shell, login shell,any shell) can run
$arm-linux-gcc
while root must use
#/usr/local/arm/bin/arm-linux-gcc

this is a similiar behaviour like
root can run
#ifconfig
while user must use
$/sbin/ifconfig

you know what I mean?

Tnx.

--edit--
fyi, i use slackware 11 upgraded from 10.2.If that matter....


All times are GMT -5. The time now is 06:10 AM.