bug-bash
[Top][All Lists]
Advanced

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

Re: nullglob option breaks complex parameter expansion/deletion


From: Michael Wardle
Subject: Re: nullglob option breaks complex parameter expansion/deletion
Date: Sun, 03 Jul 2005 08:20:49 +1000

On Sat, 2005-07-02 at 12:24 -0400, Chet Ramey wrote:
> Michael Wardle wrote:
> > Hi Chet
> > 
> > Thanks for your very prompt reply.
> > 
> > I understand that globbing is happening, but I don't understand why
> > deleting a parameter should occur with nullglob set if the parameter
> > matches but the word to delete doesn't.  The bash behavior seems to make
> > this construct useful only for file name deletion if nullglob is set,
> > when it seems to be useful for any substring deletion if nullglob is
> > unset.
> 
> The word in question is *not* being parameter expanded.  It is the
> result of a *different* parameter expansion:  the unquoted expansion
> of $connectioninfo.

I wasn't saying that the right-hand side was being parameter expanded.
I was trying to use the wording in the POSIX standard, which states:
"The word shall be expanded to produce a pattern."  I think this is
supposed to refer to file name expansion (globbing), but I confess to
being confused by this wording myself.

> Since the results of the parameter expansion of $connectioninfo are
> subject to filename expansion, the unquoted `*' in that word is run
> through *normal filename expansion*.  Since that expansion looks only
> for filenames and, since nullglob is set, deletes words containing
> globbing operators that don't match filenames, the word ends up being
> removed.

I understand that normal file name expansion is occurring, but I can't
see any use for it in this construct.  I would be happy to learn of such
a use, but in the absence of one, I would advocate the parameter
deletions such as ${parameter%word} be a special case not subject to
nullglob.

> You might get a clearer picture of what's happening if you ran
> 
>       echo "$connectioninfo"
> 
> and inhibited the filename expansion that normally takes place.

I believe my followup exhibited this understanding.

> > I also noticed in the POSIX standard that quoting the word part should
> > cause it to be literal and prevent globbing.  If I try this in bash, I
> > get the same result as in my original message, that is:
> 
> You have misunderstood which expansion needs to be quoted.  It's the
> expansion of $connectioninfo that needs quoting, as above.

POSIX says this:
${x#"*"}
        The literal asterisk is quoted and not special.

Which leads me to believe that quoting the asterisk should have the
desired result, and certainly at least a different result from that
which I am seeing.

Again, I don't understand why nullglob is useful inside ${parameter%%
word}, and it's certainly not obvious why quoting the right-hand side
should be necessary.






reply via email to

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