[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Some minor $*-like expansion issues
From: |
Grisha Levit |
Subject: |
Some minor $*-like expansion issues |
Date: |
Sat, 2 Mar 2019 22:08:27 -0500 |
A few silly (and admittedly unlikely to be encoutered) cases where the
behavior of certain expansions that should presumably mirror that of
$* differs.
With null IFS, leading/trailing spaces are removed from ${*:N} when
used for assignment:
$ IFS=''
$ set -- ' X '
$ x=$* y=${*:1}; printf '<%s>\n' "$x" "$y"
< X >
<X>
$ unset x y; printf '<%s>\n' ${x=$*} ${y=${*:1}}
< X >
<X>
With null IFS associative array keys are joined by space when used for
assignment:
$ IFS=''
$ set -- b a
$ declare -A A=([b]= [a]=)
$ x=$* y=${!A[*]}; printf '<%s>\n' "$x" "$y"
<ba>
<b a>
$ unset x y; printf '<%s>\n' ${x=$*} ${y=${!A[*]}}
<ba>
<b a>
...and are expanded as a single field joined with spaces on the RHS of PE:
$ unset x y; printf '<%s>\n' ${x-$*} ${y-${!A[*]}}
<b>
<a>
<b a>
And a couple of issues with indirect expansion of * that have some
overlap with the above.
With:
$ IFS=:
$ set -- a b
$ ind=*
Space is used to join fields instead of the first char of IFS here:
$ x=$* y=${!ind}; printf '<%s>\n' "$x" "$y"
<a:b>
<a b>
And a single field joined with spaces is produced here:
$ unset x y; printf '<%s>\n' ${x-$*} ${y-${!ind}}
<a>
<b>
<a b>
$ unset x y; printf '<%s>\n' ${x=$*} ${y=${!ind}}
<a>
<b>
<a b>
Leading and trailing spaces are removed when the first character of
IFS is space or IFS is null or unset in this assignment case:
$ set -- ' X '
$ ind='*'
$ IFS=$' \t\n'
$ x=$* y=${!ind}; printf '<%s>\n' "$x" "$y"
< X >
<X>
$ IFS=''
$ x=$* y=${!ind}; printf '<%s>\n' "$x" "$y"
< X >
<X>
Perhaps related to some of the above, in the below cases, \001 and
\177 or combinations thereof are not properly treated, e.g.:
$ IFS=''
$ set -- $'\177'
$ var=${*:1}; printf '<%q>\n' "$var"
<''>
$ unset var; printf '<%q>\n' ${var=${*:1}}
<''>
Same for:
declare -a a=($'\177')
var=${a[*]:0}; printf '<%q>\n' "$var"
unset var; printf '<%q>\n' ${var=${a[*]:0}}
set -- $'\177'; ind='*'
var=${!ind}; printf '<%q>\n' "$var"
unset var; printf '<%q>\n' ${var=${!ind}}
Just for completeness, though this expansion is documented to be undefined:
declare -A A=([0]=$'\177')
var=${A[*]:0}; printf '<%q>\n' "$var"
unset var; printf '<%q>\n' ${var=${A[*]:0}}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Some minor $*-like expansion issues,
Grisha Levit <=