bug-bash
[Top][All Lists]
Advanced

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

Re: Unexpected word splitting on $* when IFS is unset


From: Robert Elz
Subject: Re: Unexpected word splitting on $* when IFS is unset
Date: Fri, 23 Jun 2017 22:27:44 +0700

    Date:        Thu, 22 Jun 2017 07:51:12 -0400
    From:        Greg Wooledge <wooledg@eeg.ccf.org>
    Message-ID:  <20170622115111.GQ22519@eeg.ccf.org>


  | $ dash
  | $ set -- a b
  | $ IFS=
  | $ args $*
  | 1 args: <ab>

That is simply broken.  Always has been, whatever mistakes were
in the wording posix used to use to try and explain how it works.

  | $ ksh
  | $ set -- a b
  | $ IFS=
  | $ args $*
  | 2 args: <a> <b>

This has always been the correct behaviour.  There is no field splitting
happening, but when unquoted, there's no joining happening either.
$* is just $1 $2 ... (for as many params as set) as separate words.

That is, if you knew how many words existed, and wrote it out in longhand
in the first place.  $* is just convenient when you don't know how many
params there are.

When quoted ("$*"), IFS[0] is used to turn the words into the string required,
when unquoted they are just words.  "$@" is the one slightly weird special
case, but only because it is defined to be "$1" "$2" ... (for as many
params as exist, including 0).

kre




reply via email to

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