Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


  Search this Thread
Old 09-03-2003, 12:40 AM   #1
LQ Newbie
Registered: Sep 2003
Posts: 3

Rep: Reputation: Disabled
Question BASH export command

My shell script enviroment variables are not exported (yes, I used export) to the parent shell. This is true of root and user accounts. Although, /etc/profile script env. vars export correctly. This occured after I upgraded to Slackware 9.0.

Here is the sample script I am debugging:
# Foobar script
FOOBAR="Hello World"
export FOOBAR
Then I try,
somebody@network:~# ./
somebody@network:~# echo $FOOBAR

, but this works:

somebody@network:~# FOOBAR="Hello World"; export FOOBAR
somebody@network:~# echo $FOOBAR
Hello World
Yes, my script has exec permission. I am hoping I don't have to recompile bash (like I did for ISC dhclient, because something is broken in the package - I had to use the source tarball from ISC). And many hours/google searches later I ended up here. Any Ideas?

Thanks in adv. for any help (/sympathy)!!
Old 09-03-2003, 02:29 AM   #2
LQ Newbie
Registered: Jul 2003
Distribution: Slackware
Posts: 10

Rep: Reputation: 0
I may be wrong but I think enviroment variables in bash scripts are supposed to be used within the script.

Here, to setup 'global' bash variables, I use ~/.bash_profile


export CHARSET=ISO8859-1
Old 09-03-2003, 05:08 AM   #3
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
. ./

dot first !
Old 09-06-2003, 11:20 PM   #4
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
The export command makes the value of a variable available to the current process and to subprocesses, but not to parent processes!

When you create a shell script and execute it, a new shell process is started to execute the contents of that script. Any exported variable values are available to the new shell, or to any subprocesses the new shell creates. When the script ends, none of the exported variable values are available to the parent process (your login shell).

When you log in, the first thing that the login shell does is runs your login script (e.g. ~/.bash_profile), which is why any exported variable values in that script are available to you from that point on.

Adding the . before you execute (for example: . ./ will work. The . is a shell builtin command that causes the script to be read and executed in the current shell process rather than starting a new shell process to do that. That is why exported variable values are available to your login shell. You can do the same thing with "source ./" since source and . mean the same thing.
Old 09-08-2003, 12:44 AM   #5
LQ Newbie
Registered: Sep 2003
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you! I forgot about the source command (I need to brush up on my BASH scripting).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
export call in bash script Donald1000 Linux - Software 10 03-12-2009 08:03 PM
setenv - bash - export allelopath Linux - General 4 04-17-2005 05:38 AM
set and export using bash script acummings Linux - General 10 01-03-2005 02:22 PM
sticking export $LFS in bash file glock19 Linux From Scratch 7 01-29-2002 06:58 PM
BASH variable export Barbarian Programming 2 11-27-2001 08:37 PM > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration