what does export do?

Kenneth Porter shiva at sewingwitch.com
Fri May 20 22:07:39 UTC 2005


--On Friday, May 20, 2005 11:00 PM +0100 THUFIR HAWAT 
<hawat.thufir at gmail.com> wrote:

> "source the script" means write a script?  pardon, would you expand on
> that sentence, please?

When you "execute" a script by typing its name at the command line, the 
current shell spawns another shell as a child process to interpret and run 
the script. Sometimes you want to run the commands in a script in the 
current shell, not in a child. For Bash you can do that by putting ". " 
(dot space) in front of the script's name. The dot command is built into 
the shell and reads commands from its argument filename, executing them 
directly.

For instance, if you have a script that sets shell variables, you don't 
want to run it in a subshell (a child process) as that won't affect the 
variables in the current shell. Instead, you want want to "source"  it into 
the current shell, running it as if you typed its contents in at the prompt.

A common use of this in Fedora is in the initscripts in /etc/rc.d/init.d. 
They source scripts full of program settings from scripts in /etc/sysconfig.





More information about the fedora-list mailing list