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


Groups > gnu.bash.bug > #14430

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 09:03 -0400
Message-ID <mailman.4549.1533128642.1292.bug-bash@gnu.org> (permalink)
References <c1978119-1836-e88d-4889-c54bea4d0559@iki.fi> <20180801121251.efyquoibrsneiqbl@eeg.ccf.org> <360e6d91-f959-ef2e-a349-9286542890b7@passchier.net>

Show all headers | View raw


On Wed, Aug 01, 2018 at 07:42:30PM +0700, pepa65 wrote:
> On 08/01/2018 07:12 PM, Greg Wooledge wrote:
> > This just reinforces the point that unquoted $@ or $* (or the array
> > equivalent) is a bug in the script.  It gives unpredictable results.
> 
> If the results are unpredictable, isn't that a bug that wants fixing?
> That would be a very noble goal, should it not be possible?

Maybe, but for a script writer, it's already too late.  Unless you fast
forward 20-30 years into the future when EVERY shell has had these bugs
fixed for long enough that you can be reasonably confident that your
script will not be executed by one of the older shell versions.

Isn't it simpler just not to write buggy scripts in the first place?

"$@" expands to a list of words, and "$*" expands to a single string
with an optional single-character delimiter inserted between substrings.
Those are the only two options you've got.

What's the intent of a script that uses unquoted $@ or $*?  What did
the script's author think was going to happen?  If it's one of the two
cases above, then the missing quotes are simply a bug in the script.
If it's something else, then I'd be interested in hearing it.

I don't speak for Chet on any of these issues.  He may feel an obligation
to fix bash if he perceives the behavior as a bug.  That's independent
of whether a script writer should actually USE such syntax.

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 09:03 -0400

csiph-web