source bash config from perl code

source bash config from perl code

Tzafrir Cohen tzafrir at cohens.org.il
Thu Oct 1 12:57:02 IST 2009


On Wed, Sep 30, 2009 at 05:57:39PM +0200, Itay Donenhirsch wrote:
> here's an idea - change the "callee" script to a bash script which
> sources the config file, and then call the real perl script. something
> along:
> 
> #!/bin/bash
> source config.env
> ./script.pl $*

1. bashism:

you meant:

#!/bin/sh
. config.env
./script.pl $*

2. What about parameters with spaces?
   s/$*/"$@"/

3. Save some extra space on the the PID table:

  exec ./script.pl

3. You still need to export the variables to make them available in the
environment of the shell script:

  export $EXPORTED_VARS


So, something along the lines of:

#!/bin/sh

# Allow overriding the list in the config: is this a feature or a bug?
EXPORTED_VARS="foo bar baz"

. config.env
export $EXPORTED_VARS

exec ./script.pl "$@"

-- 
Tzafrir Cohen         | tzafrir at jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzafrir at cohens.org.il |                    |  best
ICQ# 16849754         |                    | friend



More information about the Linux-il mailing list