[Top][All Lists]

[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: Philip Lijnzaad
Subject: Re: last `set option value' always passed as $1 and $2 during a 'source' ??
Date: 11 Jun 2001 18:59:49 +0100

On 11 Jun 2001 13:34:21 -0400, 
"Paul" == Paul Jarc <address@hidden> wrote:

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

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

ah ... thanks!

>> 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.

Paul> If a sourced script expect parameters, the caller might choose to
Paul> provide them by using 'set' rather than by passing them on the
Paul> 'source' command line.  

But if I want to write a general purpose little script, it can't use any
arguments, because it doesn't know if these arguments were explicitly typed
in, or where still 'lying around' in the environment (which was the bug I was

Paul> The script shouldn't worry about which method
Paul> the caller used.  

But I do worry; it lead to fairly obscure errors, due to someone having
changed his setup. 

Paul> The only problem here is that (AFAIK) it's impossible to pass an empty
Paul> parameter list to the script without modifying the caller's own
Paul> parameter list.

yes, that's another problem. It may be that this is Bourne-shell legacy, of
course, in which case I'll just live with it (and anyway, since it seems
that in some cases this behaviour is being  used). Many thanks,

If you have a procedure with 10 parameters, you probably missed some. (Kraulis)
Philip Lijnzaad, address@hidden \ European Bioinformatics Institute,rm A2-08
+44 (0)1223 49 4639                 / Wellcome Trust Genome Campus, Hinxton
+44 (0)1223 49 4468 (fax)           \ Cambridgeshire CB10 1SD,  GREAT BRITAIN

reply via email to

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