[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to add dir to path



Manon Metten wrote:

Thanks for explaining. So I understand that export PATH=~/scripts:$PATH
concatenates "~/scripts" and "$PATH" and sets the result to be the new
$PATH.

I do believe he's got it... almost.

If ENV_VAR is an environment variable, then the shell interprets
$ENV_VAR as a request to remove $ENV_VAR from the command, and replace
it with the value of ENV_VAR. So...

$ ENV_VAR1="Fred Flintstone"
$ ENV_VAR2=$ENV_VAR

sets ENV_VAR2 to be the value of ENV_VAR at the time of the assignment,
or "Fred Flintstone".

$ ENV_VAR2=ENV_VAR

sets ENV_VAR2 to be "ENV_VAR1".

So

$ PATH=xyz:$PATH

sets PATH (not $PATH) to be the string "xyz:" followed by
the value PATH had before the assignment took place.

We could also do this...

$ ENV_VAR=PATH
$ $ENV_VAR=xyz:$PATH

So, $ENV_VAR evaluates to PATH, which is what gets put into
there. This is not the way to do it, mind you. It's just an
illustration of how bash works.

This is kinda like on my old Amiga where I have a 'path' command, but
where I must use the ADD option, otherwise the path would be replaced
(like using export PATH=~/scripts):
path ~/scripts add == export PATH=~/scripts:$PATH

If I want an environment variable available all the time, I should place it
in
either /etc/profile or ~/.bash_profile, right?

The first affects all users on the system, the latter affects you,
so long as you continue to use bash. Switch to csh, and it won't

You might also look into the use of ~/.bashrc
BTW, it's common to use $HOME instead of "~" as not all tools
know to expand it when it is used in environment variables.
Like this:

$ export PATH=$HOME/scripts:$PATH

The environment variable HOME gets set during login.
Anyway, on my machine using $HOME gives /home/jmccarty,
which can be used by any tool in any environment variable.
using "~" is ok in this circumstance, because it's in PATH,
which mostly gets looked at by bash, and other tools like
which or what, and they are smart.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!



Reply to: