bug-bash
[Top][All Lists]
Advanced

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

$* vs ${ARRAY[*]} differences in some parameter expansions


From: Grisha Levit
Subject: $* vs ${ARRAY[*]} differences in some parameter expansions
Date: Fri, 24 Feb 2017 17:59:42 -0500

bash currently handles all parameter expansions with $* and $@ as described in interpretation 888, and the behavior when using an array subscripted with @ matches identically the behavior of the examples concerning $@.  However, the behavior when using an array subscripted with * does not always match the behavior of the examples concerning $*.

This difference is surprising since otherwise the behaviors are identical (though I'm not sure if would be proper to call this a "bug" since the isomorphism is not explicitly defined in the documentation).


$ set -- "abc" "def ghi" "jkl"
$ A=("$@")

----

$ IFS=':'

$ unset var; printf '%s\n' ${var-$*}
abc
def ghi
jkl

$ unset var; printf '%s\n' ${var-${A[*]}}
abc def ghi jkl

----

$ unset  var; printf '%s\n' ${var=$*}
abc
def ghi
jkl
$ printf 'var=%s\n' "$var"
var=abc:def ghi:jkl

$ unset var; printf '%s\n' ${var=${A[*]}}
abc def ghi jkl
$ printf 'var=%s\n' "$var"
var=abc def ghi jkl

----

$ IFS=''

$ unset var; printf '%s\n' ${var-$*}
abcdef ghijkl

$ unset var; printf '%s\n' ${var-${A[*]}}
abc
def ghi
jkl

----

$ unset var; printf '%s\n' ${var=$*}
abcdef ghijkl
$ printf 'var=%s\n' "$var"
var=abcdef ghijkl

$ unset var; printf '%s\n' ${var=${A[*]}}
abc
def
ghi
jkl
$ printf 'var=%s\n' "$var"
var=abc def ghi jkl


reply via email to

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