[Top][All Lists]

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

Re: Unquoted array slice address@hidden:0} expands to just one word if I

From: Greg Wooledge
Subject: Re: Unquoted array slice address@hidden:0} expands to just one word if IFS doesn't have a space
Date: Wed, 1 Aug 2018 10:19:01 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Aug 01, 2018 at 09:05:20PM +0700, Robert Elz wrote:
>     Date:        Wed, 1 Aug 2018 09:03:20 -0400
>     From:        Greg Wooledge <address@hidden>

>   | What's the intent of a script that uses unquoted $@ or $*?
> Either (or both) of field splitting of the args, or filename expansion.
> As in
>       set -- '*.c' '*.h'

OK, let's run with that.

wooledg:/tmp/x$ touch "file one.txt" file2.txt
wooledg:/tmp/x$ set -- '*.txt'
wooledg:/tmp/x$ args $*
2 args: <file2.txt> <file one.txt>

At this point one may think, "Hey, this is actually working.  That Greg
guy doesn't know what he's talking about!"

Now, what if we want to glob for the files that have spaces?  Here's
the glob that matches them:

wooledg:/tmp/x$ args *\ *
1 args: <file one.txt>

So we should be able to put that glob in the positional parameter list
and use your unquoted $* trick, right?

wooledg:/tmp/x$ set -- '* *'
wooledg:/tmp/x$ args $*
4 args: <file2.txt> <file one.txt> <file2.txt> <file one.txt>

It's a disaster, as I said.  It works ONLY IN THE STUPIDLY SIMPLE CASES
and then falls apart as soon as you do anything more.  Like putting
spaces in the glob.  Or setting IFS to the empty string.

This is not a "hobby horse".  This is real.

And people wonder why I'm cranky all the time.

reply via email to

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