fixed a bug with expanding unquoted $* when the separator is not whitespace and one or more of the positional parameters ends with the separator, resulting in an extra blank field being generated; fixed an issue with adjusting SHLVL in subshells that caused the environment to be rebuilt too many times; fix to make sure function substitution doesn't leave the -v option unset

This commit is contained in:
Chet Ramey
2026-05-20 10:18:32 -04:00
parent 669b32f676
commit 2d4ba0c618
15 changed files with 503 additions and 36 deletions
+5
View File
@@ -266,6 +266,11 @@ test_runsub ./dollar-at-star9.sub
test_runsub ./dollar-at-star10.sub
test_runsub ./dollar-at-star11.sub
# tests for unquoted expansions of $* and $@ when word splitting will take
# place and the separator is not whitespace
test_runsub ./dollar-at-star12.sub
test_runsub ./dollar-at-star13.sub
# tests for special expansion of "$*" and "${array[*]}" when used with other
# expansions -- bugs through bash-2.05b
test_runsub ./dollar-star1.sub
+60
View File
@@ -0,0 +1,60 @@
OIFS=$IFS
set -- a b+ c +d e; IFS=+;
# these should be the same
printf '<%s> ' $1 $2 $3 $4 $5; echo
printf '<%s> ' $* ; echo
printf '<%s> ' $@ ; echo
set -- 'b+' 'c'
# these should be the same
echo =====
printf '<%s> ' $1 $2 $3; echo
printf '<%s> ' $* ; echo
printf '<%s> ' $@ ; echo
printf '<%s> ' ${*} ; echo
printf '<%s> ' ${@} ; echo
# these should be the same
echo =====
set -- a 'b+c' '+d+e' 'f+g+' h
printf '<%s> ' $* ; echo
printf '<%s> ' $@ ; echo
echo =====
array=(a 'b+' c '+d' e)
printf '<%s> ' ${array[0]} ${array[1]} ${array[2]} ${array[3]} ${array[4]}; echo
printf '<%s> ' ${array[*]} ; echo
printf '<%s> ' ${array[@]} ; echo
unset array
array=(a 'b+c' '+d+e' 'f+g+' h)
printf '<%s> ' ${array[0]} ${array[1]} ${array[2]} ${array[3]} ${array[4]}; echo
printf '<%s> ' ${array[*]} ; echo
printf '<%s> ' ${array[@]} ; echo
unset array
echo =====
set -- $'\001\177+' 'b+' c; IFS=+;
recho $1 $2 $3
recho $*
set -- $'\177+' 'b+' c; IFS=+;
recho $1 $2 $3
recho $*
set -- $'a\177+' 'b+' c; IFS=+;
recho $1 $2 $3
recho $*
set -- $'\001+' b+ c; IFS=+;
recho $1 $2 $3
recho $*
set -- $'a\001+' b+ c; IFS=+;
recho $1 $2 $3
recho $*
+41
View File
@@ -0,0 +1,41 @@
# from back in 2018 on dash@vger.kernel.org
# IFS the default, these arguments should not be split
set -- , ,
IFS=,
recho $@
recho $*
recho ${@}
recho ${*}
set -- $@
recho $#
# IFS already set, these arguments should be split
set -- , ,
recho $@
recho $*
recho ${@}
recho ${*}
set -- $@
recho $#
# need the space to be preserved
set -- , ' ,'
IFS=,
recho $@
recho $*
set -- $@
recho $#
# need the , to preserve an empty argument before the trailing char
# from back in 2018 on dash@vger.kernel.org
set -- ',' ','
recho ${@}a
recho ${*}b
recho a${@}
recho b${*}
+91 -10
View File
@@ -247,22 +247,18 @@ argv[3] = <'c'>
argv[1] = <>
argv[2] = <a>
argv[3] = <>
argv[4] = <>
argv[5] = <b>
argv[6] = <>
argv[7] = <>
argv[8] = <c>
argv[4] = <b>
argv[5] = <>
argv[6] = <c>
argv[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'c'>
argv[1] = <>
argv[2] = <a>
argv[3] = <>
argv[4] = <>
argv[5] = <b>
argv[6] = <>
argv[7] = <>
argv[8] = <c>
argv[4] = <b>
argv[5] = <>
argv[6] = <c>
argv[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'c'>
@@ -477,6 +473,91 @@ argv[1] = <>
argv[1] = <>
argv[1] = </>
1:1
dollar-at-star12.sub
<a> <b> <c> <> <d> <e>
<a> <b> <c> <> <d> <e>
<a> <b> <c> <> <d> <e>
=====
<b> <c>
<b> <c>
<b> <c>
<b> <c>
<b> <c>
=====
<a> <b> <c> <> <d> <e> <f> <g> <h>
<a> <b> <c> <> <d> <e> <f> <g> <h>
=====
<a> <b> <c> <> <d> <e>
<a> <b> <c> <> <d> <e>
<a> <b> <c> <> <d> <e>
<a> <b> <c> <> <d> <e> <f> <g> <h>
<a> <b> <c> <> <d> <e> <f> <g> <h>
<a> <b> <c> <> <d> <e> <f> <g> <h>
=====
argv[1] = <^A^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <^A^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <a^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <a^?>
argv[2] = <b>
argv[3] = <c>
argv[1] = <^A>
argv[2] = <b>
argv[3] = <c>
argv[1] = <^A>
argv[2] = <b>
argv[3] = <c>
argv[1] = <a^A>
argv[2] = <b>
argv[3] = <c>
argv[1] = <a^A>
argv[2] = <b>
argv[3] = <c>
dollar-at-star13.sub
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <2>
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <>
argv[2] = <>
argv[1] = <2>
argv[1] = <>
argv[2] = < >
argv[1] = <>
argv[2] = < >
argv[1] = <2>
argv[1] = <>
argv[2] = <>
argv[3] = <a>
argv[1] = <>
argv[2] = <>
argv[3] = <b>
argv[1] = <a>
argv[2] = <>
argv[1] = <b>
argv[2] = <>
dollar-star1.sub
xa|xb|xc
xa|xb|xc
+1 -1
View File
@@ -1,4 +1,4 @@
unset GROUPS UID 2>/dev/null
unset GROUPS 2>/dev/null
${THIS_SH} ./test.tests >${BASH_TSTOUT} 2>&1
diff ${BASH_TSTOUT} test.right && rm -f ${BASH_TSTOUT}