Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14434

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space
Date 2018-08-01 10:19 -0400
Message-ID <mailman.4557.1533133154.1292.bug-bash@gnu.org> (permalink)
References <20180801130320.wwmnw6ixxztihj3i@eeg.ccf.org> <c1978119-1836-e88d-4889-c54bea4d0559@iki.fi> <20180801121251.efyquoibrsneiqbl@eeg.ccf.org> <360e6d91-f959-ef2e-a349-9286542890b7@passchier.net> <22714.1533132320@jinx.noi.kre.to>

Show all headers | View raw


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 <wooledg@eeg.ccf.org>

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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space Greg Wooledge <wooledg@eeg.ccf.org> - 2018-08-01 10:19 -0400

csiph-web