bug-bash
[Top][All Lists]
Advanced

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

extra field in $* expansion when non-whitespace character in IFS


From: Grisha Levit
Subject: extra field in $* expansion when non-whitespace character in IFS
Date: Sun, 9 Apr 2017 19:35:17 -0400

In most cases, removing a non-whitespace IFS character "delimits" a field
in the sense that it terminates it, so the presence of such a character at
the end of a field does not change its expansion:

  $ IFS=X
  $ set -- Y; printf '<%s>' $*
  <Y>
  $ set -- YX; IFS=X; printf '<%s>' $*
  <Y>

However, when a positional parameter ends with a non-whitespace IFS character
and is followed by another positional parameter, the removal of the IFS
character seems to create an additional field:

  $ set -- YX Y; printf '<%s>' $*
  <Y><><Y>

Is this intentional? It sort of makes sense since $* is expanded as if it
were $1c$2 (where c is the first character of IFS), i.e. the expansion above
matches what is produced by

  set -- YX Y; v=$*; printf '<%s>' $v

but that doesn't seem to respect the prescribed behavior of first producing
a field for each positional parameter, and then subjecting each field to
field splitting.

Array behavior matches positional parameter behavior here.

FWIW, this differs from the ksh behavior:

  $ set -- YX Y; printf '<%s>' $*
  <Y><Y>



reply via email to

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