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 14:25:03 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

Philip Lijnzaad <address@hidden> writes:
>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
> hunting). 

It can use arguments.  It can't tell how the caller specified the
arguments, but it shouldn't care.  If it got the wrong arguments
because the caller didn't pass any extra arguments on the 'source'
command line and had some extra arguments left in its own list, then
that's a bug in the caller, not the script.  The bug should be fixed,
not worked around, and it's not necessary to avoid useful
functionality such as passing arguments to sourced scripts.  The
caller simply must take care to correctly use the interface of
'source' and the script.

I agree that the interface of 'source' is not a good one, and it can
lead to problems that may be hard to diagnose.  But consistent
awareness of the potential problems tends to prevent them.

> It may be that this is Bourne-shell legacy,

It certainly isn't unique to bash.  Solaris sh doesn't even let you
pass arguments to the sourced script on the 'source' command line -
the sourced script always sees the caller's positional parameters.


paul



reply via email to

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