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


Groups > gnu.bash.bug > #14434 > unrolled thread

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

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2018-08-01 10:19 -0400
Last post2018-08-01 10:19 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

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

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2018-08-01 10:19 -0400
SubjectRe: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space
Message-ID<mailman.4557.1533133154.1292.bug-bash@gnu.org>
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.

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web