source bash config from perl code
Tzafrir Cohen
tzafrir at cohens.org.il
Sun Oct 4 03:22:29 IST 2009
On Sat, Oct 03, 2009 at 08:17:49PM +0200, Oleg Goldshmidt wrote:
>
> Tzafrir Cohen <tzafrir at cohens.org.il> writes:
>
> > Having to export what you explicitly set is a strange habbit for a
> > configuration format.
>
> Why? Doesn't your ~/.bash_profile export what it needs to?
That file is not merely a 'key->value' configuration format.
(Not to mention the simple fact that it breaks the existing code,
according to the description in the thread: simple inclusion in a shell
script).
>
> >> #!/bin/bash
> >>
> >> function die() {
> >
> > Nit #1: you can get rid of 'function' and save a whole word while making
> > the script more portable.
>
> It is explicitly a bash script,
Which is generally what I want to avoid if I don't need bash.
> and "function" adds to readability. It's a question of style.
Fine.
> Where you seem to be very focused on tiny savings,
Nah, you lost me there. BTW: if I were concerened about saving I would
simply replace '#!/bin/bash' with '#!/bin/sh' . On a system where
/bin/sh is dash, this actually saves a bit of time.
> >> # now run the rest of the command line
> >>
> >> $@
> >
> > Nit #4: "$@"
>
> Think again: what if the command line contains quoted strings? You
> might argue (having certain use cases in mind) that "$@" is preferable
> - the point is that they are not equivalent.
Huh?
withenv "$HOME/My Environment/משתני סביבה.env" "perl script" "arg 1" "arg 2"
($1 is unquoted further up which will make it fail there in the example)
>
> >> Note that a command line that refers to environment variables will
> >> expand them before the $environment is sourced.
> >
> > $@ is expanded after reading the configuration. But why should it matter
> > (unless you use very dirty tricks) ?
>
> No need for dirty tricks. The case I had in mind is something like
>
> $ withenv config.env echo $PATH
>
> - if config.env sets PATH it won't be picked up as the shell expands
> $PATH in the command line before withenv is called.
So you meant: 'by the calling shell'. PATH has already been expanded
before the wrapper script was called.
--
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