[SWLUG] Bash Export Question

Gareth Bowker bowkerg at teccon.co.uk
Thu Apr 24 13:52:37 UTC 2003


On Thu, 2003-04-24 at 11:40, SPUFI Doo wrote:
> Hi,
> 
> I've a really simple question I can't get my newbie head around...
> I have a bash script which signs me on to a database, and I would like it to export the database
> name into a variable DATABASE.
>    #!/usr/bin/env bash
>    db2 attach to awdpss user db2admin using db2admin
>    db2 connect to misqwpdb user db2admin using db2admin
>    export DATABASE=`db2 get connection state | grep alias | awk -F"= " '{print $2}'`
>    export INSTANCE=`db2 attach | grep alias | awk -F" = " '{print $2}'`
> 
> If I run the command
>    export DATABASE=`db2 get connection state | grep alias | awk -F"= " '{print $2}'`
> on the command line, echo $DATABASE returns the correct value, but if I include it at the end of
> my bash script, echo $DATABASE returns nothing.
> 
> What am I doing wrong?

Child shell scripts' variables don't propagate to the parent. If you
want to do that, try:

source ./script.sh

or

. ./script.sh

Gareth
-- 
Gareth Bowker           | <bowkerg at teccon.co.uk>
Software Engineer       | http://www.thetcl.com/
Technology Concepts Ltd | +44 870 870 5088
-- 
The Wireless LAN event  22nd-23rd of May
Europe's Only Dedicated Wireless LAN Exhibition, Olympia, London
Visit us at stand 37a





More information about the Swlug mailing list