[ale] Bash scripts for idiots...
Wandered Inn
esoteric at denali.atlnet.com
Sat Nov 6 09:13:47 EST 1999
Benjamin Scherrey wrote:
>
> Ah ha! That's it! Thanx. Only - that's really screwy. I would never
> have imagined in a million years that I'd have to prepend my script
> execution with a '.' to get it running within my environment. Seems
> kinda silly. I should expect that you'd have to specify something
> explicit (like appending a '&' at the end of the execution or called
> exec()) to force the new process environment. Wonder how I managed to
> never run into this issue before!
The way the shell works is that whenever you execute a program, whether
it's a shell or a compiled executable, it starts up a child process to
do it. Once the child process dies, it takes with it, it's environment.
The child inherits it's parents environment, but the parent does not
know of the child's environment. When you use the:
. myshell.sh
construct, you are invoking the shell within your current process and
not starting up a child process.
This is intentional by the way. Think about how huge your environment
would get if everytime you executed a process all the variables and such
became a part of your existing environment. On a multi-user system such
as Linux, you'd quickly run out of resources.
You can do a similar thing with an executable with the 'exec' command.
If you were to type 'sh' at the command line, you'll find that you have
two shells now running. Your original as well as the one you just
started. If you type 'exec sh' you will replace your existing shell
with 'sh'.
--
Until later: Geoffrey esoteric at denali.atlnet.com
It should be illegal to yell "Y2K" in a crowded economy.
-- Larry Wall, creator of the programming language Perl
More information about the Ale
mailing list