declare builtin changes to reject -i when used with -n; readline changes to make control characters visible in search strings; readline signal handling changes to avoid data corruption and UAF; documentation updates for more consistent quoting

This commit is contained in:
Chet Ramey
2025-09-04 12:29:57 -04:00
parent ab17ddb7af
commit a451bfc3f5
46 changed files with 36912 additions and 1499 deletions
+11 -4
View File
@@ -1,12 +1,13 @@
alias: 0
alias: 0
./alias.tests: line 38: qfoo: command not found
./alias.tests: line 44: unalias: foo: not found
./alias.tests: line 40: qfoo: command not found
./alias.tests: line 46: unalias: foo: not found
quux
hi
declare -a m=([0]="x")
./alias.tests: line 66: alias: `\$': invalid alias name
./alias.tests: line 67: `\$': invalid alias name
./alias.tests: line 68: alias: `\$': invalid alias name
./alias.tests: line 69: `\$': invalid alias name
alias1.sub
bar
value
bar
@@ -15,6 +16,7 @@ OK
OK
OK
OK
alias2.sub
one
two
three
@@ -23,6 +25,8 @@ one
two
three
four
alias3.sub
alias4.sub
Error: bar
ok 1
ok 2
@@ -40,14 +44,17 @@ bar
bad
0
<|cat>
alias5.sub
foo
bar
baz
foo
bar
baz
alias6.sub
<áa>
<aá>
alias7.sub
bar
foo bar x
foo
+9 -7
View File
@@ -12,6 +12,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# place holder for future alias testing
. ./test-aux-functions
shopt -s expand_aliases
# alias/unalias tests originally in builtins.tests
@@ -66,10 +68,10 @@ declare -p m
alias '\$'=xx
BASH_ALIASES['\$']=xx
${THIS_SH} ./alias1.sub
${THIS_SH} ./alias2.sub
${THIS_SH} ./alias3.sub
${THIS_SH} ./alias4.sub
${THIS_SH} ./alias5.sub
${THIS_SH} ./alias6.sub
${THIS_SH} ./alias7.sub
test_runsub ./alias1.sub
test_runsub ./alias2.sub
test_runsub ./alias3.sub
test_runsub ./alias4.sub
test_runsub ./alias5.sub
test_runsub ./alias6.sub
test_runsub ./alias7.sub
+3 -1
View File
@@ -15,12 +15,14 @@
4
9
16
./appendop.tests: line 97: x: readonly variable
./appendop.tests: line 99: x: readonly variable
appendop1.sub
declare -A foo=([two]="baz" [three]="quux" [one]="bar" )
declare -A foo=([0]="zero" [two]="baz" [three]="quux" [one]="bar" )
declare -A foo=([four]="four" [0]="zero" [two]="baz" [three]="quux" [one]="bar" )
declare -ai iarr=([0]="3" [1]="2" [2]="3")
declare -ai iarr=([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")
appendop2.sub
25 25
7 7
14
+4 -2
View File
@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. ./test-aux-functions
# basic cases
a=1
a+=4
@@ -96,5 +98,5 @@ echo $x
x+=5
${THIS_SH} ./appendop1.sub
${THIS_SH} ./appendop2.sub
test_runsub ./appendop1.sub
test_runsub ./appendop2.sub
+42 -31
View File
@@ -61,7 +61,7 @@
1,i+=2
30
1,j+=2
./arith.tests: line 129: 1 ? 20 : x+=2: attempted assignment to non-variable (error token is "+=2")
./arith.tests: line 131: 1 ? 20 : x+=2: attempted assignment to non-variable (error token is "+=2")
20
6
6,5,3
@@ -83,18 +83,18 @@
36
62
63
./arith.tests: line 168: 3425#56: invalid arithmetic base (error token is "3425#56")
./arith.tests: line 171: 2#: invalid integer constant (error token is "2#")
./arith.tests: line 174: 7 = 43 : attempted assignment to non-variable (error token is "= 43 ")
./arith.tests: line 175: 2#44: value too great for base (error token is "2#44")
./arith.tests: line 176: 44 / 0 : division by 0 (error token is "0 ")
./arith.tests: line 177: let: jv += $iv: arithmetic syntax error: operand expected (error token is "$iv")
./arith.tests: line 178: jv += $iv : arithmetic syntax error: operand expected (error token is "$iv ")
./arith.tests: line 179: let: rv = 7 + (43 * 6: missing `)' (error token is "6")
./arith.tests: line 182: b / 0 : division by 0 (error token is "0 ")
./arith.tests: line 183: b /= 0 : division by 0 (error token is "0 ")
./arith.tests: line 188: 0#4: invalid number (error token is "0#4")
./arith.tests: line 189: 2#110#11: invalid number (error token is "2#110#11")
./arith.tests: line 170: 3425#56: invalid arithmetic base (error token is "3425#56")
./arith.tests: line 173: 2#: invalid integer constant (error token is "2#")
./arith.tests: line 176: 7 = 43 : attempted assignment to non-variable (error token is "= 43 ")
./arith.tests: line 177: 2#44: value too great for base (error token is "2#44")
./arith.tests: line 178: 44 / 0 : division by 0 (error token is "0 ")
./arith.tests: line 179: let: jv += $iv: arithmetic syntax error: operand expected (error token is "$iv")
./arith.tests: line 180: jv += $iv : arithmetic syntax error: operand expected (error token is "$iv ")
./arith.tests: line 181: let: rv = 7 + (43 * 6: missing `)' (error token is "6")
./arith.tests: line 184: b / 0 : division by 0 (error token is "0 ")
./arith.tests: line 185: b /= 0 : division by 0 (error token is "0 ")
./arith.tests: line 190: 0#4: invalid number (error token is "0#4")
./arith.tests: line 191: 2#110#11: invalid number (error token is "2#110#11")
abc
def
ghi
@@ -102,15 +102,15 @@ ok
6
1
0
./arith.tests: line 207: 4 + : arithmetic syntax error: operand expected (error token is "+ ")
./arith.tests: line 209: 4 + : arithmetic syntax error: operand expected (error token is "+ ")
16
./arith.tests: line 212: 4 ? : 3 + 5 : expression expected (error token is ": 3 + 5 ")
./arith.tests: line 213: 1 ? 20 : `:' expected for conditional expression (error token is "20 ")
./arith.tests: line 214: 4 ? 20 : : expression expected (error token is ": ")
./arith.tests: line 214: 4 ? : 3 + 5 : expression expected (error token is ": 3 + 5 ")
./arith.tests: line 215: 1 ? 20 : `:' expected for conditional expression (error token is "20 ")
./arith.tests: line 216: 4 ? 20 : : expression expected (error token is ": ")
9
./arith.tests: line 220: 0 && B=42 : attempted assignment to non-variable (error token is "=42 ")
./arith.tests: line 222: 0 && B=42 : attempted assignment to non-variable (error token is "=42 ")
9
./arith.tests: line 223: 1 || B=88 : attempted assignment to non-variable (error token is "=88 ")
./arith.tests: line 225: 1 || B=88 : attempted assignment to non-variable (error token is "=88 ")
9
0
9
@@ -126,7 +126,7 @@ ok
131072
2147483647
1
./arith.tests: line 255: 2**-1 : exponent less than 0 (error token is "1 ")
./arith.tests: line 257: 2**-1 : exponent less than 0 (error token is "1 ")
4
4
5
@@ -137,19 +137,20 @@ ok
4
4
7
./arith.tests: line 274: 7-- : arithmetic syntax error: operand expected (error token is "- ")
./arith.tests: line 276: --x=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 277: ++x=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 279: x++=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 280: x--=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 276: 7-- : arithmetic syntax error: operand expected (error token is "- ")
./arith.tests: line 278: --x=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 279: ++x=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 281: x++=7 : attempted assignment to non-variable (error token is "=7 ")
./arith.tests: line 282: x--=7 : attempted assignment to non-variable (error token is "=7 ")
4
7
-7
7
7
./arith.tests: line 292: --x++ : ++: assignment requires lvalue (error token is "++ ")
./arith.tests: line 294: --x++ : ++: assignment requires lvalue (error token is "++ ")
2
2
arith1.sub
./arith1.sub: line 15: 4-- : arithmetic syntax error: operand expected (error token is "- ")
./arith1.sub: line 16: 4++ : arithmetic syntax error: operand expected (error token is "+ ")
./arith1.sub: line 17: 4 -- : arithmetic syntax error: operand expected (error token is "- ")
@@ -172,6 +173,7 @@ ok
7
7
./arith1.sub: line 51: ((: -- : arithmetic syntax error: operand expected (error token is "- ")
arith2.sub
7
7
7
@@ -200,6 +202,7 @@ ok
-7
7
7
arith3.sub
1
1
4
@@ -209,11 +212,13 @@ ok
4
5000
5000
arith4.sub
1
0
0
1
2147483649
arith5.sub
0
0
0
@@ -231,6 +236,7 @@ ok
-9223372036854775808
-9223372036854775808
9223372036854775805 9223372036854775806 9223372036854775807
arith6.sub
123 456
123 456
123 456
@@ -243,12 +249,14 @@ ok
0
0, 0
0, 1
arith7.sub
efg
e
efg
e
abcdefg
efg
arith8.sub
0
0
0
@@ -256,6 +264,7 @@ efg
0
0
0
arith9.sub
./arith9.sub: line 4: a: unbound variable
./arith9.sub: line 5: a: unbound variable
0
@@ -281,6 +290,7 @@ after 4 0
+ set +x
./arith9.sub: line 37: 4+: arithmetic syntax error: operand expected (error token is "+")
x = 4+ y =
arith10.sub
== arraysub ==
=== assoc_expand_once unset ===
declare -a a=([0]="10")
@@ -355,6 +365,7 @@ declare -a a=([0]="0")
3 1
./arith10.sub: line 95: let: 0 - "": arithmetic syntax error: operand expected (error token is """")
4 1
arith11.sub
0
declare -a yy=([0]="10")
@@ -365,14 +376,14 @@ declare -a yy=([0]="10")
Y
./arith11.sub: line 65: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
8 12
./arith.tests: line 338: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
./arith.tests: line 342: a b: arithmetic syntax error in expression (error token is "b")
./arith.tests: line 343: ((: a b: arithmetic syntax error in expression (error token is "b")
./arith.tests: line 340: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
./arith.tests: line 344: a b: arithmetic syntax error in expression (error token is "b")
./arith.tests: line 345: ((: a b: arithmetic syntax error in expression (error token is "b")
42
42
42
42
42
42
./arith.tests: line 358: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
./arith.tests: line 361: b[c]d: arithmetic syntax error in expression (error token is "d")
./arith.tests: line 360: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
./arith.tests: line 363: b[c]d: arithmetic syntax error in expression (error token is "d")
+13 -11
View File
@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. ./test-aux-functions
set +o posix
declare -i iv jv
@@ -296,36 +298,36 @@ unset -v x
echo $(( "`echo 1+1`" ))
echo $(( `echo 1+1` ))
${THIS_SH} ./arith1.sub
${THIS_SH} ./arith2.sub
${THIS_SH} ./arith3.sub
${THIS_SH} ./arith4.sub
test_runsub ./arith1.sub
test_runsub ./arith2.sub
test_runsub ./arith3.sub
test_runsub ./arith4.sub
# make sure arithmetic expansion handles ints > 2**31 - 1 using intmax_t
echo $(( 2147483645 + 4 ))
# other tests using INTMAX_MIN and INTMAX_MAX that cause exceptions if not
# handled correctly -- problem through bash-4.2
${THIS_SH} ./arith5.sub
test_runsub ./arith5.sub
# problems with suppressing evaluation present through bash-4.2
${THIS_SH} ./arith6.sub
test_runsub ./arith6.sub
# problems with parsing arithmetic expressions containing colons that are
# part of word expansions such as substring extraction
${THIS_SH} ./arith7.sub
test_runsub ./arith7.sub
# problems with evaluation of conditional expressions
${THIS_SH} ./arith8.sub
test_runsub ./arith8.sub
# expressions with unset variables and nounset enabled
${THIS_SH} ./arith9.sub
test_runsub ./arith9.sub
# empty expressions in various arithmetic evaluation contexts
${THIS_SH} ./arith10.sub
test_runsub ./arith10.sub
# internal quoting for array subscripts
${THIS_SH} ./arith11.sub
test_runsub ./arith11.sub
x=4
y=7
+58 -25
View File
@@ -1,12 +1,12 @@
./array.tests: line 34: syntax error near unexpected token `&'
./array.tests: line 34: `test=(first & second)'
./array.tests: line 35: syntax error near unexpected token `&'
./array.tests: line 35: `test=(first & second)'
1
abcde
abcde
abcde bdef
abcde bdef
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -26,7 +26,7 @@ hello world
11
3
bdef hello world test expression test 2
./array.tests: line 98: readonly: `a[5]': not a valid identifier
./array.tests: line 99: readonly: `a[5]': not a valid identifier
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
declare -ar c
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
@@ -34,7 +34,7 @@ declare -ar c
readonly -a a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
readonly -a c
a test
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -46,18 +46,18 @@ declare -ar c
declare -a d=([1]="" [2]="bdef" [5]="hello world" [6]="test" [9]="ninth element")
declare -a e=([0]="test")
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
./array.tests: line 122: a: readonly variable
./array.tests: line 124: b[]: bad array subscript
./array.tests: line 125: b[*]: bad array subscript
./array.tests: line 123: a: readonly variable
./array.tests: line 125: b[]: bad array subscript
./array.tests: line 126: b[*]: bad array subscript
this
./array.tests: line 128: c[-2]: bad array subscript
./array.tests: line 129: c: bad array subscript
./array.tests: line 129: c[-2]: bad array subscript
./array.tests: line 130: c: bad array subscript
./array.tests: line 131: d[7]: cannot assign list to array member
./array.tests: line 133: []=abcde: bad array subscript
./array.tests: line 134: [*]=last: cannot assign to non-numeric index
./array.tests: line 135: [-65]=negative: bad array subscript
declare -a BASH_ARGC=()
./array.tests: line 132: d[7]: cannot assign list to array member
./array.tests: line 134: []=abcde: bad array subscript
./array.tests: line 135: [*]=last: cannot assign to non-numeric index
./array.tests: line 136: [-65]=negative: bad array subscript
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -69,13 +69,13 @@ declare -ar c
declare -a d=([1]="test test")
declare -a e=()
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
./array.tests: line 143: unset: ps1: not an array variable
./array.tests: line 147: declare: c: readonly variable
./array.tests: line 144: unset: ps1: not an array variable
./array.tests: line 148: declare: c: readonly variable
this of
this is a test of read using arrays
this test
this is a test of arrays
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -123,7 +123,7 @@ argv[1] = </>
55
49
6 -- 6
./array.tests: line 238: [-10]: bad array subscript
./array.tests: line 239: [-10]: bad array subscript
0
42 14 44
grep [ 123 ] *
@@ -131,20 +131,24 @@ grep [ 123 ] *
6 7 9 5
length = 3
value = new1 new2 new3
./array.tests: line 267: syntax error near unexpected token `&'
./array.tests: line 267: `badarray=( metacharacters like & need to be quoted in compound assignments)'
./array.tests: line 271: narray[4]: unbound variable
./array.tests: line 268: syntax error near unexpected token `&'
./array.tests: line 268: `badarray=( metacharacters like & need to be quoted in compound assignments)'
./array.tests: line 272: narray[4]: unbound variable
array1.sub
./array1.sub: line 1: syntax error near unexpected token `('
./array1.sub: line 1: `printf "%s\n" -a a=(a 'b c')'
array2.sub
./array2.sub: line 1: declare: `[]=asdf': not a valid identifier
./array2.sub: line 2: a[]: bad array subscript
./array2.sub: line 4: syntax error near unexpected token `('
./array2.sub: line 4: `declare -a ''=(a 'b c')'
array3.sub
9
9
7 8 9
array4.sub
8 11
8 11
6
@@ -160,10 +164,10 @@ for case if then else
12 14 16 18 20
4414758999202
aaa bbb
./array.tests: line 321: syntax error near unexpected token `<>'
./array.tests: line 321: `metas=( <> < > ! )'
./array.tests: line 322: syntax error near unexpected token `<>'
./array.tests: line 322: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
./array.tests: line 322: `metas=( <> < > ! )'
./array.tests: line 323: syntax error near unexpected token `<>'
./array.tests: line 323: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
abc 3
case 4
abc case if then else 5
@@ -217,11 +221,13 @@ FIN3:0
FIN4:0
FIN5:0
FIN6:0
array5.sub
t
[3]=abcde r s t u v
e
9
2
array6.sub
a b c
argv[1] = <-iname 'a>
argv[2] = <-iname 'b>
@@ -284,6 +290,7 @@ argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
array7.sub
nord!olz
rdholz
@@ -292,6 +299,7 @@ rdholz
rdho
array8.sub
argv[1] = <fooq//barq/>
argv[1] = <fooq>
argv[2] = <>
@@ -317,6 +325,7 @@ argv[1] = <FOOQ>
argv[2] = <>
argv[3] = <BARQ>
argv[4] = <>
array9.sub
126
127
128
@@ -330,6 +339,7 @@ argv[3] = <
argv[1] = <~>
argv[2] = <^?>
argv[3] = <€>
array10.sub
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Monday
Monday
@@ -359,6 +369,7 @@ ednesday
onday
uesday
ednesday
array11.sub
version[agent]
version.agent
version[agent]
@@ -369,15 +380,18 @@ foobar] foo foo[bar]
bleh bbb bleh
ab]
bar
array12.sub
1
1
1
1
1
1
array13.sub
main main
function function
function function
array14.sub
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4")
declare -a x=([0]="0" [1]="1" [2]="2" [4]="4")
@@ -389,6 +403,7 @@ declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="foo")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4four" [5]="5")
strlen(4four) = 5
array15.sub
1 2 0 3
1 2 0 3
1 2 0 3
@@ -396,6 +411,7 @@ strlen(4four) = 5
1 2 0 3
declare -ai arr=([0]="2" [1]="4" [2]="6")
declare -a arr=([0]="hello" [1]="world")
array16.sub
foo index 1: ok
foo index 2: ok
foo: implicit reference to element 0: ok
@@ -408,6 +424,7 @@ qux: unset array element 0: ok
0
0
0
array17.sub
2
2
2
@@ -431,6 +448,7 @@ one
two
two
./array17.sub: line 89: ~ : arithmetic syntax error: operand expected (error token is "~ ")
array18.sub
1
argv[1] = <>
argv[2] = <>
@@ -454,6 +472,7 @@ argv[1] = <qux>
argv[1] = <->
argv[2] = <->
argv[1] = < >
array19.sub
declare -a foo=([0]="( zeroind )")
declare -a foo=([0]="zeroind")
declare -a foo=([0]="zeroind")
@@ -498,6 +517,7 @@ declare -A b=([0]="/scratch/bash" )
declare -A c=([1]="2" )
declare -A d=(["a b"]="" )
declare -A e=([Darwin]="" )
array20.sub
a+b+c
x+b+c
a+b+c
@@ -508,6 +528,7 @@ a b c
x b c
a b c
x b c
array21.sub
declare -a a=([1]="2" [2]="3" [3]="4")
abcd
unset
@@ -516,6 +537,7 @@ declare -A A=([four]="4" [two]="2" [three]="3" [one]="1" )
declare -a a=()
declare -A A=()
declare -a foo=([0]="1" [1]="(4 5 6)" [2]="3")
array22.sub
a1
argv[1] = <>
argv[2] = <>
@@ -537,6 +559,7 @@ p3
argv[1] = <y>
<X> <X> <X> <X>
<X> <X> <X> <X>
array23.sub
./array23.sub: line 22: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
./array23.sub: line 23: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
./array23.sub: line 24: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
@@ -548,6 +571,7 @@ argv[1] = <y>
0
0
0
array24.sub
IFS=: ${var-$*}
abc
def ghi
@@ -595,6 +619,7 @@ jkl
abc
def ghi
jkl
array25.sub
1. indexed:
reference:
1. 0
@@ -639,6 +664,7 @@ arithmetic:
6.declare -A a=([1]="1" [0]="0" [" "]="10" ["\" \""]="11" )
7.declare -A a=([1]="1" [0]="0" [" "]="12" ["\" \""]="11" )
8.declare -A a=([1]="1" [0]="0" [" "]="12" ["\" \""]="13" )
array26.sub
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
@@ -759,6 +785,7 @@ argv[2] = <a>
argv[1] = <b>
argv[2] = <a>
argv[1] = <b+a>
array27.sub
7
7
declare -A A=([$'\t']="2" [" "]="2" )
@@ -774,12 +801,14 @@ declare -A A=(["*"]="X" ["@"]="X" )
declare -A A=(["*"]="X" ["@"]="X" )
./array27.sub: line 81: y[]: bad array subscript
./array27.sub: line 81: y[]: bad array subscript
array28.sub
declare -a bug4=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a bug=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a bug2=([0]="")
declare -a bug3=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a not_bug=([0]="no" [1]="nulls")
declare -a workaround=([0]="")
array29.sub
declare -a var=([0]=$'\001\001\001\001')
declare -A v2=([$'\001']=$'ab\001c' )
declare -a foo=([0]=$'\001\001\001\001')
@@ -790,6 +819,7 @@ declare -A foo=([v]=$'\001\001\001\001' )
declare -A foo=([v]=$'\001\001\001\001' )
declare -A foo=([$'\001']=$'ab\001c' )
declare -A foo=([$'\001']=$'ab\001c' )
array30.sub
foo
declare -a a=([42]="foo")
foo
@@ -802,12 +832,14 @@ FOO
declare -Au A=([Darwin]="FOO" )
FOO
declare -Au A=(["@"]="FOO" )
array31.sub
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
array32.sub
./array32.sub: line 20: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
./array32.sub: line 21: declare: a: not found
./array32.sub: line 24: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
@@ -837,6 +869,7 @@ declare -a a
declare -a a=()
./array32.sub: line 95: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
declare -a a=()
array33.sub
declare -A A=([x]="x" )
declare -A A=([1]="1" )
./array33.sub: line 27: f: A: cannot convert associative to indexed array
+34 -33
View File
@@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. ./test-aux-functions
# Filter stdin to remove builtin array variables that are
# automatically set and possibly contain values that vary.
@@ -270,14 +271,14 @@ badarray=( metacharacters like & need to be quoted in compound assignments)
set -u
( echo ${#narray[4]} )
${THIS_SH} ./array1.sub
${THIS_SH} ./array2.sub
test_runsub ./array1.sub
test_runsub ./array2.sub
# some old bugs and ksh93 compatibility tests
${THIS_SH} ./array3.sub
test_runsub ./array3.sub
# some compound assignment parsing problems that showed up in bash-3.1-release
${THIS_SH} ./array4.sub
test_runsub ./array4.sub
set +u
cd ${TMPDIR:=/tmp}
@@ -426,35 +427,35 @@ BASH_ARGV[1]=foo ; echo FIN5:$?
declare BASH_ARGV[1]=foo ; echo FIN6:$?
# tests for bash-3.1 problems
${THIS_SH} ./array5.sub
test_runsub ./array5.sub
# tests for post-bash-3.2 problems, most fixed in bash-3.2 patches
${THIS_SH} ./array6.sub
${THIS_SH} ./array7.sub
test_runsub ./array6.sub
test_runsub ./array7.sub
${THIS_SH} ./array8.sub
${THIS_SH} ./array9.sub
${THIS_SH} ./array10.sub
${THIS_SH} ./array11.sub
${THIS_SH} ./array12.sub
${THIS_SH} ./array13.sub
${THIS_SH} ./array14.sub
${THIS_SH} ./array15.sub
${THIS_SH} ./array16.sub
${THIS_SH} ./array17.sub
${THIS_SH} ./array18.sub
${THIS_SH} ./array19.sub
${THIS_SH} ./array20.sub
${THIS_SH} ./array21.sub
${THIS_SH} ./array22.sub
${THIS_SH} ./array23.sub
${THIS_SH} ./array24.sub
${THIS_SH} ./array25.sub
${THIS_SH} ./array26.sub
${THIS_SH} ./array27.sub
${THIS_SH} ./array28.sub
${THIS_SH} ./array29.sub
${THIS_SH} ./array30.sub
${THIS_SH} ./array31.sub
${THIS_SH} ./array32.sub
${THIS_SH} ./array33.sub
test_runsub ./array8.sub
test_runsub ./array9.sub
test_runsub ./array10.sub
test_runsub ./array11.sub
test_runsub ./array12.sub
test_runsub ./array13.sub
test_runsub ./array14.sub
test_runsub ./array15.sub
test_runsub ./array16.sub
test_runsub ./array17.sub
test_runsub ./array18.sub
test_runsub ./array19.sub
test_runsub ./array20.sub
test_runsub ./array21.sub
test_runsub ./array22.sub
test_runsub ./array23.sub
test_runsub ./array24.sub
test_runsub ./array25.sub
test_runsub ./array26.sub
test_runsub ./array27.sub
test_runsub ./array28.sub
test_runsub ./array29.sub
test_runsub ./array30.sub
test_runsub ./array31.sub
test_runsub ./array32.sub
test_runsub ./array33.sub
+25 -6
View File
@@ -7,15 +7,15 @@ declare -A fluff=([foo]="one" [bar]="two" )
declare -A fluff=([foo]="one" [bar]="two" )
declare -A fluff=([bar]="two" )
declare -A fluff=([qux]="assigned" [bar]="newval" )
./assoc.tests: line 39: chaff: four: must use subscript when assigning associative array
./assoc.tests: line 41: chaff: four: must use subscript when assigning associative array
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -Ai chaff=([one]="10" [zero]="5" )
declare -Ar waste=([pid]="42134" [lineno]="41" [source]="./assoc.tests" [version]="4.0-devel" )
declare -Ar waste=([pid]="42134" [lineno]="43" [source]="./assoc.tests" [version]="4.0-devel" )
declare -A wheat=([two]="b" [three]="c" [one]="a" [zero]="0" )
declare -A chaff=(["hello world"]="flip" [one]="10" [zero]="5" )
./assoc.tests: line 51: waste: readonly variable
./assoc.tests: line 52: unset: waste: cannot unset: readonly variable
./assoc.tests: line 53: waste: readonly variable
./assoc.tests: line 54: unset: waste: cannot unset: readonly variable
declare -A chaff=(["*"]="12" ["hello world"]="flip" [one]="a" )
flip
argv[1] = <multiple>
@@ -33,14 +33,14 @@ argv[3] = <12>
argv[4] = <flip>
argv[5] = <a>
argv[1] = <multiple words 12 flip a>
./assoc.tests: line 71: declare: chaff: cannot destroy array variables in this way
./assoc.tests: line 73: declare: chaff: cannot destroy array variables in this way
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
argv[1] = <qux>
argv[2] = <qix>
argv[1] = <qux qix>
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
argv[1] = <2>
./assoc.tests: line 99: [$unset]: bad array subscript
./assoc.tests: line 101: [$unset]: bad array subscript
0
argv[1] = <7>
argv[1] = <qux>
@@ -78,6 +78,7 @@ bin bin . bin ucb sbin bin sbin
\usr\local\bin \bin . \usr\bin \usr\ucb \usr\sbin \bin \sbin
\usr\local\bin \bin . \usr\bin \usr\ucb \usr\sbin \bin \sbin
([a]=1)
assoc1.sub
foo qux
/usr/sbin/foo /usr/local/bin/qux
@@ -88,6 +89,7 @@ hits command
0 /usr/local/bin/qux
foo sh blat qux
/usr/sbin/foo /bin/sh /sbin/blat /usr/local/bin/qux
assoc2.sub
foo qux
argv[1] = </usr/sbin/foo>
@@ -102,6 +104,7 @@ argv[1] = <cd /blat ; echo $PWD>
argv[2] = </usr/sbin/foo>
argv[3] = </bin/bash --login -o posix>
argv[4] = </usr/local/bin/qux -l>
assoc3.sub
outside: outside
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
@@ -110,6 +113,7 @@ argv[1] = <inside:>
argv[2] = <six>
argv[3] = <foo quux>
outside 2: outside
assoc4.sub
argv[1] = </barq//fooq>
argv[1] = <>
argv[2] = <barq>
@@ -135,6 +139,7 @@ argv[1] = <>
argv[2] = <BARQ>
argv[3] = <>
argv[4] = <FOOQ>
assoc5.sub
abc
def
def
@@ -144,6 +149,7 @@ myarray=(["]"]="def" [foo]="bleh" ["a]a"]="abc" ["a]=test1;#a"]="123" )
123
myarray=(["]"]="def" ["a]=test2;#a"]="def" [foo]="bleh" ["a]a"]="abc" ["a]=test1;#a"]="123" )
assoc6.sub
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
@@ -189,6 +195,7 @@ declare -A foo=(["bar\\]bie"]="doll" )
bar${foo}bie
doll
declare -A foo=(["bar\${foo}bie"]="doll" )
assoc7.sub
bar
after printf
after use: 0
@@ -198,6 +205,8 @@ declare -A assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -Ar assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -A hash=([key]="value1" )
declare -A hash=([key]="value1 value2" )
assoc8.sub
assoc9.sub
declare -A b=([")"]="" ["\""]="" ["]"]="" ["\\"]="" ["\`"]="" )
declare -A b=(["]"]="" ["\`"]="" )
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
@@ -228,6 +237,7 @@ declare -A assoc=()
foo]bar
bip
declare -A foo=(["foo]bar"]="bip" )
assoc10.sub
./assoc10.sub: line 14: declare: a: cannot convert indexed to associative array
f: declare -a a
./assoc10.sub: line 17: declare: a: cannot convert associative to indexed array
@@ -237,6 +247,7 @@ f: declare -a a
main: declare -- a="7"
f: declare -A a
main: declare -- a="42"
assoc11.sub
declare -A a=([3]="" [1]="2" )
declare -A foo=([d]="4" [c]="3" [b]="2" [a]="1" )
foo=( d "4" c "3" b "2" a "1" )
@@ -263,6 +274,7 @@ declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
declare -Arx foo=([two]="2" [three]="3" [one]="1" )
./assoc11.sub: line 90: foo: readonly variable
assoc12.sub
declare -A v1=(["1 2"]="3" )
declare -A v2=(["1 2"]="3" )
declare -A v3=(["1 2"]="3" )
@@ -281,6 +293,7 @@ declare -A v3=(["1 2"]="3 4 5" ["\$xtra"]="xtra" )
declare -A v1=(["20 40 80"]="new xtra" ["1 2"]="3 4 5" )
declare -A v2=(["20 40 80"]="new xtra" ["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" ["\$xtra"]="new xtra" )
assoc13.sub
declare -A assoc=(["*"]="star" ["!"]="bang" ["@"]="at" )
at
star
@@ -290,6 +303,7 @@ declare -a ia
declare -A a=(["@"]="at2" )
declare -A a=(["@"]=" string" )
declare -A a=(["*"]="star2" ["@"]="at" )
assoc14.sub
declare -A assoc=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
argv[1] = <world>
argv[2] = <value with spaces>
@@ -331,6 +345,7 @@ argv[7] = <'foo'>
argv[8] = <'bar'>
declare -A clone=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
declare -A posparams=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
assoc15.sub
declare -A var=([$'\001']=$'\001\001\001\001' )
declare -A v2=([$'\001']=$'\001\001\001\001' )
argv[1] = <^A>
@@ -354,6 +369,7 @@ declare -A var=([two]=$'ab\001cd' [one]=$'\001\001\001\001' )
declare -A foo=([two]=$'ab\001cd' [one]=$'\001\001\001\001' )
declare -A foo=([$'\001']=$'ab\001cd' )
declare -A foo=([$'\001']=$'\001\001\001\001' )
assoc16.sub
declare -A A=(["\$(echo Darwin ; echo stderr>&2)"]="darjeeling" [Darwin]="darjeeling" )
stderr
darjsharking
@@ -385,6 +401,7 @@ set
stderr
42
42
assoc17.sub
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
@@ -395,11 +412,13 @@ declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
assoc18.sub
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
5: ok 1
assoc19.sub
declare -A aa=([key]="/homes/cj/Desktop" )
declare -A aa=([key]="/homes/cj/Desktop" )
declare -A aa=([k2]="/homes/cj/Library" [key]="/homes/cj/Desktop" )
+21 -19
View File
@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. ./test-aux-functions
# TEST - basic declaration and assignment
typeset -A fluff
declare -A
@@ -199,19 +201,19 @@ if [ "$T" != "${T[0]}" ]; then
echo 'assoc.tests: $T and ${T[0]} mismatch'
fi
${THIS_SH} ./assoc1.sub
test_runsub ./assoc1.sub
${THIS_SH} ./assoc2.sub
test_runsub ./assoc2.sub
${THIS_SH} ./assoc3.sub
test_runsub ./assoc3.sub
${THIS_SH} ./assoc4.sub
test_runsub ./assoc4.sub
${THIS_SH} ./assoc5.sub
test_runsub ./assoc5.sub
${THIS_SH} ./assoc6.sub
test_runsub ./assoc6.sub
${THIS_SH} ./assoc7.sub
test_runsub ./assoc7.sub
# test converting between scalars and assoc arrays
unset assoc
@@ -240,36 +242,36 @@ declare -p hash
unset hash
${THIS_SH} ./assoc8.sub
test_runsub ./assoc8.sub
# new shopt option to prevent multiple expansion of assoc array subscripts
${THIS_SH} ./assoc9.sub
test_runsub ./assoc9.sub
${THIS_SH} ./assoc10.sub
test_runsub ./assoc10.sub
# test assigning associative arrays using compound key/value pair assignments
${THIS_SH} ./assoc11.sub
test_runsub ./assoc11.sub
# more kvpair associative array assignment tests
${THIS_SH} ./assoc12.sub
test_runsub ./assoc12.sub
# assignment to @ and *
${THIS_SH} ./assoc13.sub
test_runsub ./assoc13.sub
# tests of the @k transformation on associative arrays
${THIS_SH} ./assoc14.sub
test_runsub ./assoc14.sub
# tests with subscripts and values containing 0x01 (some indexed array tests too)
${THIS_SH} ./assoc15.sub
test_runsub ./assoc15.sub
# tests with subscripts being expanded more than one in ${xxx} word expansions
${THIS_SH} ./assoc16.sub
test_runsub ./assoc16.sub
# tests with `[' and `]' subscripts and `unset'
${THIS_SH} ./assoc17.sub
test_runsub ./assoc17.sub
# tests with `[' and `]' subscripts and printf/read/wait builtins
${THIS_SH} ./assoc18.sub
test_runsub ./assoc18.sub
# tests with tilde expansion in keys and values post-bash-5.2
${THIS_SH} ./assoc19.sub
test_runsub ./assoc19.sub
+5 -3
View File
@@ -1,13 +1,14 @@
after f1:declare -ar a=([0]="1")
./attr.tests: line 17: f2: a: readonly variable
./attr.tests: line 19: f2: a: readonly variable
after f2:declare -ar a=([0]="1")
./attr.tests: line 18: a: readonly variable
./attr.tests: line 20: a: readonly variable
after f3:declare -ar a=([0]="1")
./attr.tests: line 19: readonly: a: readonly variable
./attr.tests: line 21: readonly: a: readonly variable
after f4:declare -ar a=([0]="1")
after f2:declare -ar b=([0]="2")
after f3:declare -ar c=([0]="(3)")
after f4:declare -ar d=([0]="4")
attr1.sub
declare -r m="4"
in func:declare -r n="4"
declare -r n="4"
@@ -30,6 +31,7 @@ in func:declare -ar y1=([0]="4")
declare -ar y1=([0]="4")
in func:declare -ar z1=([0]="4")
declare -ar z1=([0]="4")
attr2.sub
declare -x p="4"
declare -ax r=([0]="4")
declare -ax r=([0]="(5)")
+4 -3
View File
@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
. ./test-aux-functions
a=(outside)
f1() { readonly a=(1) ; }
@@ -49,6 +51,5 @@ f4
echo -n after f4:
declare -p d
${THIS_SH} ./attr1.sub
${THIS_SH} ./attr2.sub
test_runsub ./attr1.sub
test_runsub ./attr2.sub
+1 -1
View File
@@ -81,7 +81,7 @@ echo and ${word-${ echo work here; }}
unset x
set -- 'a[${ break;}]'
declare -in x
declare -n x
for x do :; done
echo after for
+1 -1
View File
@@ -148,7 +148,7 @@ ${THIS_SH} ./exec6.sub
# checks for properly deciding what constitutes an executable file
${THIS_SH} ./exec7.sub
${THIS_SH} -i ${PWD}/exec8.sub
HISTFILE= ${THIS_SH} --norc -i ${PWD}/exec8.sub
${THIS_SH} ./exec9.sub
+4 -3
View File
@@ -534,7 +534,7 @@ declare -a array=([0]="one" [1]="two" [2]="three")
declare -ai a=([0]="5")
declare -ai a=([0]="6")
declare -ai a=([0]="42")
./nameref23.sub: line 28: declare: a[0]: expands to invalid variable name for name reference
./nameref23.sub: line 28: declare: cannot use -n with -i
declare -ai a=([0]="1")
./nameref23.sub: line 29: declare: b: not found
declare -ai a=([0]="1")
@@ -546,10 +546,11 @@ declare -- b="110"
./nameref23.sub: line 39: declare: `1': invalid variable name for name reference
declare -ai a=([0]="1")
./nameref23.sub: line 41: declare: b: not found
./nameref23.sub: line 48: declare: cannot use -n with -i
declare -ai a=([0]="4")
declare -in b="a[0]"
declare -n b="a[0]"
declare -ai a=([0]="6")
declare -in b="a[0]"
declare -n b="a[0]"
foo
foo bar
declare -a a=([0]="" [1]="foo bar")
+1 -1
View File
@@ -45,7 +45,7 @@ unset a ; unset -n b
#####
declare -ai a=('4');
declare -n b='a[0]';
declare -ni b; # this should maybe not be allowed, but it is for now
declare -ni b; # this is now disallowed; doesn't change attributes
declare -p a b
b+=2;