bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: last `set option value' always passed as $1 and $2 during a 'source'


From: Paul Jarc
Subject: Re: last `set option value' always passed as $1 and $2 during a 'source' ??
Date: 11 Jun 2001 13:34:21 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

Philip Lijnzaad <lijnzaad@ebi.ac.uk> writes:
> So the question now is: why does ``set foo bar'' change $1 and $2 ? Is this
> documented? If so, where ?

Right about where you'd expect.  man bash:
       set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
              [...] Any arguments remaining after the options are
              processed are treated as values for the positional
              parameters and are assigned, in order, to $1, $2, ...
              $n.

> More importantly, why?

Probably because it's a useful feature.  My Makefile generator
manipulates the positional parameters extensively.  (I think this is
why it runs so slowly.)

> It renders the passing of parameters to source'd scripts unusable,
> since you can't distinguish between parameters that happen to come
> from the calling environment, and those passed in as arguments from
> the the ``source script args'' invocation.

If a sourced script expect parameters, the caller might choose to
provide them by using 'set' rather than by passing them on the
'source' command line.  The script shouldn't worry about which method
the caller used.  The only problem here is that (AFAIK) it's
impossible to pass an empty parameter list to the script without
modifying the caller's own parameter list.


paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]