Simple Bash Script Question

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Mon, 28 Jan 2002 08:07:57 -0700


On the off chance you haven't already gotten fifty replies on this:

> I am having trouble exporting a shell variable from a Bash script.
> 
> Here is the script test.sh:
> #! /bin/sh
> echo it works
> export IA32ROOT="/opt/intel/compiler50/ia32"
> echo done
> 
> Here is the output:
> [root@localhost bin]# ./test.sh
> it works
> done
> [root@localhost bin]# echo $IA32ROOT
> 
> [root@localhost bin]#
> 
> As you can see, there is no export nor any error...

When you run it in a script like that, you fork a subshell to run the
script. It runs just fine. Insert an echo $IA32ROOT statement in your script
and you will see it. But when the script ends, so does the subshell.

It's apparently your desire to set the value of that variable in your
running shell. To do that, "source" the script by running it with the "."
(dot) command:

. ./test.sh

should do it for you.

-- 
Lynn David Newton
Phoenix, Arizona