On 05/07/10 09:40, [email protected] wrote:
> I have a trivial script to set and env var and export it .
> 
> DELAY=16
> 
>  cat  /usr/local/bin/cron_delay.sh
> #!/bin/sh
> # work around challenged crontabs
> # set env var for cronjob
> export  DELAY=15
> 
>  /usr/local/bin/cron_delay.sh
>  echo $DELAY
> 16
> 
> 
> /bin/sh
> 
> BusyBox v1.17.0.git (2010-05-27 20:35:42 CEST) built-in shell (ash)
> Enter 'help' for a list of built-in commands.
> 
> 
> 
> Why does export not work ?

Because you can't modify the parent process's environment variables.
When you run /usr/local/bin/cron_delay.sh, you are creating a new
process which executes /bin/sh (with the pathname of the script as its
first argument).  That new process can modify it's own environment
variables and pass them on to processes it creates, but it can't modify
the environment of its parent process.  This is a standard unix feature,
not a bug.

It's possible to run the script within the current shell process
(instead of spawning a new process) using the "source" or "." built-in
shell command:

 source /usr/local/bin/cron_delay.sh

Since it's the current shell process that's running the commands in the
script, any changes to environment variables will be in the current
shell process, and will be passed on to any other processes created by
the current shell process.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to