bug-bash
[Top][All Lists]
Advanced

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

Re: $# equals 1 in scripts sourced with no arguments from a login shell


From: Paul Jarc
Subject: Re: $# equals 1 in scripts sourced with no arguments from a login shell when bash 1.x vars are set
Date: 12 Jun 2001 10:57:15 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

Dmckeon@swcp.com (Denis McKeon) writes:
> This is a different manifestation of the problem Philip posted about,
> caused in this case by a left-over relic in a bash v1 ~/.bash_profile.

And the explanation is the same.  This is intended, documented
behavior.  It has nothing to do with login shells or startup files,
and everything to do with the 'set' and 'source' commands.

> # It seems like the underlined results should be:
> # 
> # in arg0 :-bash: with dollarhash :0:
> # 
> # or if not, why not?

Not, because if you don't provide any extra arguments to 'source'
(which is your only option with traditional sh), the positional
parameters are unchanged, just like the man page says.  This is
traditional sh behavior, so it's too late to change it now.

> # attempts to turn off the behavior
> 
> $ unset command_oriented_history

unset doesn't affect positional parameters.  If you want to clear the
positional parameters, use shift until $# is 0.  (You can also use
'set --' to clear them all at once, but that's not portable to other
sh interpreters.)

> Fix: 0) don't source scripts that examine their arguments

       0') Take care to set a meaningful set of positional parameters
           before sourcing scripts that examine them.

>      1) hack bash 2.x to warn about attempts to set legendary bash 1.x vars

Any such attempt is also a meaningful (but different) thing to do with
bash 2, though.  bash 1 is the oddball here; it's incompatible with
traditional sh.


paul



reply via email to

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