[TriLUG] bash script question
jeremyp at pobox.com
jeremyp at pobox.com
Mon Aug 20 17:28:26 EDT 2001
On Mon, 20 Aug 2001, Chris Merrill wrote:
> I have a number of scripts that run various development
> tasks for me (compile, unit test, etc.). Each of them
> need to check/set some environment variables before
> doing their work...and they all need to do the same thing
> with those variables. I tried writing a 'slave' script
> to do this job, but then realized that invoking the slave
> script from within the other scripts would not work,
> since it would simply set the environment in a child
> process...which would then be lost when the slave script
> completes.
Bash (and sh) has a "." command, also called "source", which allows
you to read-in a file as if it were the current script, without executing
as a child processes. This way you can set the environment like you
describe.
For example, to test my .bashrc I usually do this:
$ . .bashrc
That is a little cryptic so I would suggest using the "source" keyword
instead. Do "man bash" and search on "source" for the whole scoop.
Hope this helps,
Jeremy
--
My software never has bugs. It just develops random features.
More information about the TriLUG
mailing list