Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14433
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Robert Elz <kre@munnari.OZ.AU> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space |
| Date | Wed, 01 Aug 2018 21:05:20 +0700 |
| Lines | 74 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.4556.1533132437.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> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | usenet.stanford.edu 1533132437 4702 208.118.235.17 (1 Aug 2018 14:07:17 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | bug-bash@gnu.org |
| To | Greg Wooledge <wooledg@eeg.ccf.org> |
| Envelope-to | bug-bash@gnu.org |
| In-Reply-To | <20180801130320.wwmnw6ixxztihj3i@eeg.ccf.org> |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2001:3c8:9009:181::2 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash/> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| Xref | csiph.com gnu.bash.bug:14433 |
Show key headers only | View raw
Date: Wed, 1 Aug 2018 09:03:20 -0400
From: Greg Wooledge <wooledg@eeg.ccf.org>
Message-ID: <20180801130320.wwmnw6ixxztihj3i@eeg.ccf.org>
| "$@" 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.
No they aren't, the third is the unquoted form (where $@ and $* are
the same, so we don't get 4 cases).
| 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'
where
echo $@
is quite different to
echo "$@"
which is (a little) different to
echo "$*"
(in that the latter separates $1 from $2 by the first char of IFS
whereas the previous one uses a space). Of course if the
command were not "echo" they would be more different.
Please get off your "always quote" hobbyhorse. In many situations
that is good advice, but not always.
| What did the script's author think was going to happen?
[jinx]$ set -- 'a b' c
[jinx]$ echo $#
2
[jinx]$ set -- $@
[jinx]$ echo $#
3
That is what I expect, and want, to happen. In this case, field splitting,
just as if I had written
set -- $1 $2
There's no special case, or magic, involved when $@ or $* is used instead
of listing the args separately (except the shell works out how many args
need be listed, instead of me...)
| If it's one of the two cases above,
It isn't.
| then the missing quotes are simply a bug in the script.
Indeed, it would be. But as it isn't...
| If it's something else, then I'd be interested in hearing it.
Is your interest satisfied now?
| 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.
It is indeed, and as the case in question is a private bash (ksh too??)
extension, bash (aka Chet) gets to decide what the behaviour should be.
But for the simple cases ($@ and $*) posix says what should happen,
users are entitled to expect that (and as far as I can tell, with bash,
they get that) and also to use it, if that's what they need to happen.
kre
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space Robert Elz <kre@munnari.OZ.AU> - 2018-08-01 21:05 +0700
csiph-web