[Techtalk] Newbie & crontab

Kathryn Hogg kjh at flyballdogs.com
Wed Nov 17 01:46:48 EST 2004


Conor Daly said:
>> Wouldn't it be also needed an "export PATH" command in
>> case some other commands are called that could need
>> the PATH environment variable, or am I wrong?
>
> While I'm not entirely clear on what 'export' does,

export adds the named environment variable to the set of environment
variables that are passed to children.

$ BOGUS=yes            # defines bogus as a local shell variable
$ set | grep BOGUS=    # verify that its set
BOGUS=yes
$ bash -c "set | BOGUS="  # spawn a child and see if its set
$ export BOGUS          # export it as an environment variable
$ bash -c "set | BOGUS="
BOGUS=yes

> It's not necessary here.
> Once I set PATH in my script, anything that script calls will get $PATH as
> set.

Most likely PATH had been previously exported.  You don't need to do it
everytime you change the value of PATH

> 'export PATH' is used where you wish a variable to persist after the
> script has run.  However, I can't seem to make that happen...

That's because you can't directly affect the evironment of your parent
process.  Each process has its own environment variables.  They are a set
of
NAME=value strings.  When a child process is run, it is done via one of
the exec(2) family of functions.  In our case, execve() is the interesting
one as it allows you to pass a set of environment variables to the child
process.

The only way I know of to modify environment variables in a parent process
is to have the parent process evaluate the output of a child command.

For example create a little script named set_bogus,
#!/bin/bash
echo BOGUS=bush

$ set_bogus
BOGUS=bush

but this of course doesn't set it in our current shell.
$ eval $(set_bogus)

will run set_bogus, replace its output on the command line and then eval
it as shell input.

-- 
Kathryn
http://womensfooty.com



More information about the Techtalk mailing list