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

Re: shell script/export question

On Sat, 2006-03-04 at 12:07 -0800, bruce wrote:
> hi..
> i have the following simple script...
> # .foo
> # User specific environment and startup programs
> JAVA_HOME=/opt/IBMJava2-141
> export JAVA_HOME
> -------------------
> when i do a >./foo.sh, and then do a echo $JAVA_HOME, i don't see the
> exported variable. foo.sh has the exe bit set (777). any idea what i'm doing
> wrong. i'm using fc4. i'm basically trying to figure out how to create a env
> var, and export the var.

Put the commands in .bash_profile or .bashrc instead.

The reason this doesn't work is that you are running the commands in a
separate shell. So the environment variables are set in that shell, and
it promptly exits. Unlike Windows .BAT files, environment variables
changed in child shells don't affect their parent.

If you want the variables set in the corrent shell, you need to set them
in the current shell. The way to do this is to use the "source" (or ".")

$ source .foo


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