Bash-4.4 distribution sources and documentation

This commit is contained in:
Chet Ramey
2016-09-15 16:59:08 -04:00
parent 30a978b7d8
commit a0c0a00fc4
588 changed files with 130746 additions and 80164 deletions
+8
View File
@@ -10,3 +10,11 @@ OK
OK
OK
OK
one
two
three
four
one
two
three
four
+1
View File
@@ -37,3 +37,4 @@ foo bar
unalias foo bar baz
${THIS_SH} ./alias1.sub
${THIS_SH} ./alias2.sub
+22
View File
@@ -0,0 +1,22 @@
THIS=alias2
FN=$TMPDIR/$THIS.script
cat > $FN <<'EOF'
#
(echo "$1")
EOF
chmod u+x $FN
shopt -s expand_aliases
alias foo1='$FN one; source $FN two; source $FN three; $FN four'
alias foo2='$FN one
source $FN two
source $FN three
$FN four'
foo1
foo2
rm -f $FN
+5 -5
View File
@@ -16,11 +16,11 @@
9
16
./appendop.tests: line 84: x: readonly variable
declare -A foo='([one]="bar" [two]="baz" [three]="quux" )'
declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -ai iarr='([0]="3" [1]="2" [2]="3")'
declare -ai iarr='([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")'
declare -A foo=([two]="baz" [three]="quux" [one]="bar" )
declare -A foo=([two]="baz" [0]="zero" [three]="quux" [one]="bar" )
declare -A foo=([two]="baz" [0]="zero" [three]="quux" [four]="four" [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")
25 25
7 7
14
+12 -4
View File
@@ -141,6 +141,8 @@ ok
-7
7
7
2
2
./arith1.sub: line 2: 4-- : syntax error: operand expected (error token is "- ")
./arith1.sub: line 3: 4++ : syntax error: operand expected (error token is "+ ")
./arith1.sub: line 4: 4 -- : syntax error: operand expected (error token is "- ")
@@ -234,14 +236,20 @@ ok
0
0, 0
0, 1
efg
e
efg
e
abcdefg
efg
8 12
./arith.tests: line 286: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
./arith.tests: line 290: a b: syntax error in expression (error token is "b")
./arith.tests: line 291: ((: a b: syntax error in expression (error token is "b")
./arith.tests: line 294: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
./arith.tests: line 298: a b: syntax error in expression (error token is "b")
./arith.tests: line 299: ((: a b: syntax error in expression (error token is "b")
42
42
42
42
42
42
./arith.tests: line 302: b[c]d: syntax error in expression (error token is "d")
./arith.tests: line 310: b[c]d: syntax error in expression (error token is "d")
+8
View File
@@ -260,6 +260,10 @@ echo $(( -7 ))
echo $(( ++7 ))
echo $(( --7 ))
# combinations of expansions
echo $(( "`echo 1+1`" ))
echo $(( `echo 1+1` ))
${THIS_SH} ./arith1.sub
${THIS_SH} ./arith2.sub
${THIS_SH} ./arith3.sub
@@ -275,6 +279,10 @@ ${THIS_SH} ./arith5.sub
# problems with suppressing evaluation present through bash-4.2
${THIS_SH} ./arith6.sub
# problems with parsing arithmetic expressions containing colons that are
# part of word expansions such as substring extraction
${THIS_SH} ./arith7.sub
x=4
y=7
+11
View File
@@ -0,0 +1,11 @@
PARAM=abcdefg
echo ${PARAM:1 ? 4 : 2}
echo ${PARAM:1 ? 4 : 2:1}
echo ${PARAM: 4<5 ? 4 : 2}
echo ${PARAM: 5>4 ? 4 : 2:1}
echo ${PARAM:${OFFSET:-0}}
OFFSET=4
echo ${PARAM:${OFFSET:-0}}
+179 -65
View File
@@ -6,15 +6,15 @@ abcde
abcde
abcde bdef
abcde bdef
declare -a BASH_ARGC='()'
declare -a BASH_ARGV='()'
declare -a BASH_LINENO='([0]="0")'
declare -a BASH_SOURCE='([0]="./array.tests")'
declare -a DIRSTACK='()'
declare -a FUNCNAME='([0]="main")'
declare -a a='([0]="abcde" [1]="" [2]="bdef")'
declare -a b='()'
declare -ar c='()'
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
declare -a DIRSTACK=()
declare -a FUNCNAME
declare -a a=([0]="abcde" [1]="" [2]="bdef")
declare -a b
declare -ar c
abcde bdef
abcde bdef
abcde
@@ -27,25 +27,25 @@ hello world
3
bdef hello world test expression test 2
./array.tests: line 76: 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")'
declare -ar c='()'
readonly -a a='([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")'
readonly -a c='()'
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")
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_ARGV='()'
declare -a BASH_LINENO='([0]="0")'
declare -a BASH_SOURCE='([0]="./array.tests")'
declare -a DIRSTACK='()'
declare -a FUNCNAME='([0]="main")'
declare -ar a='([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")'
declare -a b='([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")'
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")'
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
declare -a DIRSTACK=()
declare -a FUNCNAME
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
declare -a b=([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")
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 100: a: readonly variable
./array.tests: line 102: b[]: bad array subscript
./array.tests: line 103: b[*]: bad array subscript
@@ -57,35 +57,35 @@ declare -a f='([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element
./array.tests: line 111: []=abcde: bad array subscript
./array.tests: line 111: [*]=last: cannot assign to non-numeric index
./array.tests: line 111: [-65]=negative: bad array subscript
declare -a BASH_ARGC='()'
declare -a BASH_ARGV='()'
declare -a BASH_LINENO='([0]="0")'
declare -a BASH_SOURCE='([0]="./array.tests")'
declare -a DIRSTACK='()'
declare -a FUNCNAME='([0]="main")'
declare -ar a='([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")'
declare -a b='([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")'
declare -ar c='()'
declare -a d='([1]="test test")'
declare -a f='([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")'
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
declare -a DIRSTACK=()
declare -a FUNCNAME
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
declare -a b=([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")
declare -ar c
declare -a d=([1]="test test")
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
./array.tests: line 119: unset: ps1: not an array variable
./array.tests: line 123: declare: c: cannot destroy array variables in this way
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_ARGV='()'
declare -a BASH_LINENO='([0]="0")'
declare -a BASH_SOURCE='([0]="./array.tests")'
declare -a DIRSTACK='()'
declare -a FUNCNAME='([0]="main")'
declare -ar a='([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")'
declare -a b='([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")'
declare -ar c='()'
declare -a d='([1]="test test")'
declare -a f='([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")'
declare -a rv='([0]="this" [1]="is" [2]="a" [3]="test" [4]="of" [5]="read" [6]="using" [7]="arrays")'
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
declare -a DIRSTACK=()
declare -a FUNCNAME
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
declare -a b=([0]="this" [1]="is" [2]="a" [3]="test" [4]="" [5]="/etc/passwd")
declare -ar c
declare -a d=([1]="test test")
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
declare -a rv=([0]="this" [1]="is" [2]="a" [3]="test" [4]="of" [5]="read" [6]="using" [7]="arrays")
abde
abde
bbb
@@ -351,8 +351,8 @@ version[agent]
version.agent
version[agent] foo[bar]
version.agent bowl
foobar] foo foo[bar]
bleh bbb bleh
foo foobar] foo[bar]
bbb bleh bleh
ab]
bar
1
@@ -364,22 +364,22 @@ bar
main main
function function
function function
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")'
./array14.sub: line 11: [-10]: bad array subscript
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="five")'
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" [5]="5foo")'
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")'
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")
./array14.sub: line 11: unset: [-10]: bad array subscript
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="five")
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" [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
1 2 xx 3
1 2 0 3
1 2 xx 3
1 2 0 3
1 2 xx 3
1 2 0 3
1 2 0 3
1 2 0 3
foo index 1: ok
foo index 2: ok
foo: implicit reference to element 0: ok
@@ -388,3 +388,117 @@ bar: array with element zero unset: ok
bar: element zero: ok
qux: unset array: ok
qux: unset array element 0: ok
2
2
2
2
0
0
1
2
0
0
3
3
0
0
zero
zero
one
one
one
one
two
two
./array17.sub: line 76: ~ : syntax error: operand expected (error token is "~ ")
1
argv[1] = <>
argv[2] = <>
argv[3] = <>
argv[1] = <bar>
argv[1] = <-->
argv[1] = <>
argv[1] = <qux>
argv[1] = <->
argv[2] = <->
argv[1] = < >
argv[1] = <>
argv[2] = <>
argv[3] = <>
argv[1] = <bar>
argv[1] = <-->
argv[1] = <>
argv[1] = <qux>
argv[1] = <->
argv[2] = <->
argv[1] = < >
declare -a foo=([0]="( zeroind )")
declare -a foo=([0]="zeroind")
declare -a foo=([0]="zeroind")
declare -a foo=([0]="[0]=bar")
declare -a foo=([0]="[0]=bar")
declare -a foo=([0]="[0]=bar")
declare -- a="(1 2 3)"
declare -a a=([0]="1" [1]="2" [2]="3")
./array19.sub: line 46: a: 1: must use subscript when assigning associative array
./array19.sub: line 46: a: 2: must use subscript when assigning associative array
./array19.sub: line 46: a: 3: must use subscript when assigning associative array
declare -A a=()
declare -- a="([0]=a [1]=b)"
declare -a a=([0]="a" [1]="b")
declare -A a=([0]="a" [1]="b" )
declare -a var=([0]="[\$(echo" [1]="total" [2]="0)]=1" [3]="[2]=2]")
declare -a var=([0]="[\$(echo total 0)]=1 [2]=2]")
declare -a var=([0]="[\$(echo" [1]="total" [2]="0)]=1" [3]="[2]=2]")
./array19.sub: line 81: total 0: syntax error in expression (error token is "0")
declare -a var=()
declare -al foo=([0]="abcde" [1]="two" [2]="three")
declare -al foo=([0]="abcde")
declare -al ar=([0]="one" [1]="two" [2]="three")
declare -a a=([2]="foo")
declare -a a=([2]="foo")
declare -a a=([1]="(var)" [2]="foo")
./array19.sub: line 120: warning: a[1]=(var): quoted compound array assignment deprecated
declare -a a=([1]="(var)")
declare -a a=([0]="1" [1]="2" [2]="(1 2 3)")
declare -a a=([0]="1" [1]="2" [2]="(1 2 3)")
declare -a a=([0]="1" [1]="2" [2]="3")
declare -a a=([0]="1" [1]="2" [2]="3")
declare -a a=([0]="1" [1]="2" [2]="3")
declare -- a="a b"
declare -- b="/scratch/bash"
declare -- c="(1 2)"
declare -- d="(\$a)"
declare -- e="(\$(echo Darwin))"
declare -a a=([0]="a b")
declare -a b=([0]="/scratch/bash")
declare -a c=([0]="1" [1]="2")
declare -a d=([0]="a" [1]="b")
declare -a e=([0]="Darwin")
./array19.sub: line 166: c: 1: must use subscript when assigning associative array
./array19.sub: line 166: c: 2: must use subscript when assigning associative array
./array19.sub: line 166: d: $a: must use subscript when assigning associative array
./array19.sub: line 166: e: $(echo Darwin): must use subscript when assigning associative array
declare -A a=([0]="a b" )
declare -A b=([0]="/scratch/bash" )
declare -A c=()
declare -A d=()
declare -A e=()
a+b+c
x+b+c
a+b+c
x+b+c
argv[1] = <a+b+c+d+e+f>
argv[1] = <x+b+c+d+e+f>
a b c
x b c
a b c
x b c
declare -a a=([1]="2" [2]="3" [3]="4")
abcd
unset
./array21.sub: line 17: typeset: a: not found
./array21.sub: line 20: typeset: A: not found
declare -a a=()
declare -A A=()
declare -a foo=([0]="1" [1]="(4 5 6)" [2]="3")
+5 -8
View File
@@ -384,19 +384,16 @@ ${THIS_SH} ./array6.sub
${THIS_SH} ./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
+78
View File
@@ -0,0 +1,78 @@
# this shows the expansions an array subscript undergoes before being run
# through the arithmetic evaluator
b=(0 1 2 3)
# array subscripts undergo variable expansion
a=2
echo ${b[$a]}
# array subscripts undergo command substitution
echo ${b[$(echo 2)]}
c='1+1'
d='1-+1'
# array subscripts are expanded and the expanded value is treated as an
# expression
echo ${b[$c]}
echo ${b[c]}
echo ${b[$d]}
echo ${b[d]}
# array subscripts undergo parameter expansion
set -- 1 2 3
echo ${b[$1]}
# array subscripts undergo tilde expansion
HOME=2
echo ${b[~]}
# array subscripts undergo word splitting -- bug in bash versions through 4.3
x='b[$d]'
IFS=-
echo $((x))
IFS=$' \t\n'
set -- 1 + 2
x='d'
IFS=-
echo $((x))
IFS=$' \t\n'
# start of quoting tests; make sure that subscript is treated as double
# quoted (inhibits word splitting) but that double quotes are silently
# discarded through quote removal
echo $(( $@ ))
echo "$(( $@ ))"
echo $(( "$x" ))
echo $(( "x" ))
unset a foo bar
a=(zero one two three four five six seven eight nine ten)
echo ${a[0]}
echo ${a["0"]}
foo=1
echo ${a[$foo]}
echo ${a["$foo"]}
echo ${a[foo]}
echo ${a["foo"]}
bar=2
echo ${a[" $bar "]}
echo ${a[" bar "]}
# tilde expansion is performed by array subscript expansion but not by posix
# style arithmetic expansion
HOME=2
echo $(( ~ ))
+34
View File
@@ -0,0 +1,34 @@
# arrays referenced using @ subscript and positional parameters should behave
# the same way
foo=(0 0 0); [[ -z ${foo[@]#0} ]]; echo $?
recho "${foo[@]#0}"
bar=${foo[@]#0}
recho bar
recho $bar
recho -$bar-
recho "$bar"
qux="${foo[@]#0}"
recho qux
recho $qux
recho -$qux-
recho "$qux"
unset foo qux bar
set -- 0 0 0
recho "${@#0}"
bar=${@#0}
recho bar
recho $bar
recho -$bar-
recho "$bar"
qux="${@#0}"
recho qux
recho $qux
recho -$qux-
recho "$qux"
+167
View File
@@ -0,0 +1,167 @@
# tests for changes to declare and assignment statement arguments post-bash-4.3
unset foo l a b
l="( zeroind )"
unset foo
declare -a foo
foo="$l"
declare -p foo
unset foo
declare -a foo="$l"
declare -p foo
unset foo
declare -a foo=$l
declare -p foo
b='[0]=bar'
unset foo
declare -a foo="$b"
declare -p foo
unset foo
declare -a foo=("$b")
declare -p foo
unset foo
declare -a foo=($b)
declare -p foo
unset a
declare a='(1 2 3)'
declare -p a
unset a
declare -a a
declare a='(1 2 3)'
declare -p a
unset a
declare -A a
declare a='(1 2 3)'
declare -p a
unset a
declare a='([0]=a [1]=b)'
declare -p a
unset a
declare -a a
declare a='([0]=a [1]=b)'
declare -p a
unset a
declare -A a
declare a='([0]=a [1]=b)'
declare -p a
unset a
unset var value
value='[$(echo total 0)]=1 [2]=2]'
unset var
declare -a var
var=($value)
declare -p var
unset var
declare -a var=("$value")
declare -p var
unset var
declare -a var=($value)
declare -p var
unset var
declare -a var="($value)"
declare -p var
unset foo value
value="AbCdE"
declare -a foo
foo=( one two three )
declare -l foo="$value"
declare -p foo
unset foo
value='(AbCdE)'
declare -a foo
foo=( one two three )
declare -l foo="$value"
declare -p foo
unset ar
declare -a ar=(ONE TWO THREE)
declare -al ar=(${ar[@]})
declare -p ar
unset a
declare -a a
a[2]=foo
declare -p a
unset a
declare -a a
declare a[2]=foo
declare -p a
declare a[1]='(var)'
declare -p a
unset a
declare a[1]='(var)'
declare -p a
unset a
a=(1 2 3)
a[2]='(1 2 3)'
declare -p a
unset a
a=(1 2 3)
declare a[2]='(1 2 3)'
declare -p a
unset a
a=(1 2 3)
declare a='(1 2 3)'
declare -p a
unset a
a=(1 2 3)
declare 'a=(1 2 3)'
declare -p a
unset a
declare -a a='(1 2 3)'
declare -p a
unset a b c d e x y
HOME=/scratch/bash
x='a b'
y='($(echo Darwin))'
declare a=$x b=~ c='(1 2)' d='($a)' e=$y
declare -p a b c d e
unset a b c d e
declare -a a=$x b=~ c='(1 2)' d='($a)' e=$y
declare -p a b c d e
unset a b c d e
declare -A a=$x b=~ c='(1 2)' d='($a)' e=$y
declare -p a b c d e
+34
View File
@@ -0,0 +1,34 @@
# tests to make sure that $* and ${array[*]} expand consistently in `list'
# and `scalar' contexts
arr=(a b c)
IFS=+
# these two should both expand to `+' separated strings
a=${arr[*]} ; echo "$a"
b=${arr[*]/a/x}; echo "$b"
set -- a b c
# these two should both expand to `+' separated strings
a=${*} ; echo "$a"
b=${*/a/x}; echo "$b"
# these two should both expand to `+' separated strings and it should handle
# characters in IFS as chars in the string
unset a b
set -- 'a+b' 'c+d' 'e+f'
a=${*} ; recho "$a"
b=${*/a/x}; recho "$b"
# now let's make sure that @ always uses space separators even in contexts
# where we don't do word splitting
set -- a b c
a=${@} ; echo "$a"
b=${@/a/x}; echo "$b"
unset a b
a=${arr[@]} ; echo "$a"
b=${arr[@]/a/x}; echo "$b"
+37
View File
@@ -0,0 +1,37 @@
typeset -a a
a=(1 2 3 4)
typeset -A A
A=([one]=1 [two]=2 [three]=3 [four]=4)
unset 'a[0]'
typeset -p a
scalar=abcd
echo ${scalar[0]}
unset 'scalar[0]'
echo ${scalar-unset}
unset 'a[@]'
typeset -p a
unset 'A[@]'
typeset -p A
typeset -a a
a=(1 2 3 4)
typeset -A A
A=([one]=1 [two]=2 [three]=3 [four]=4)
# supported, recommended way to unset all array elements
a=()
typeset -p a
A=()
typeset -p A
declare -a foo
declare foo='(1 2 3)'
declare foo[1]='(4 5 6)'
declare -p foo
+70 -65
View File
@@ -1,23 +1,24 @@
declare -A BASH_ALIASES='()'
declare -A BASH_CMDS='()'
declare -A fluff='()'
declare -A BASH_ALIASES='()'
declare -A BASH_CMDS='()'
declare -A fluff='([bar]="two" [foo]="one" )'
declare -A fluff='([bar]="two" [foo]="one" )'
declare -A fluff='([bar]="two" )'
declare -A fluff='([bar]="newval" [qux]="assigned" )'
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A fluff
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A fluff=([bar]="two" [foo]="one" )
declare -A fluff=([bar]="two" [foo]="one" )
declare -A fluff=([bar]="two" )
declare -A fluff=([bar]="newval" [qux]="assigned" )
./assoc.tests: line 26: 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='([version]="4.0-devel" [source]="./assoc.tests" [lineno]="28" [pid]="42134" )'
declare -A wheat='([one]="a" [zero]="0" [two]="b" [three]="c" )'
declare -A chaff='([one]="10" ["hello world"]="flip" [zero]="5" )'
./assoc.tests: line 38: unset: waste: cannot unset: readonly variable
./assoc.tests: line 39: chaff[*]: bad array subscript
./assoc.tests: line 40: [*]=12: invalid associative array key
declare -A chaff='([one]="a" ["hello world"]="flip" )'
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -Ai chaff=([one]="10" [zero]="5" )
declare -Ar waste=([version]="4.0-devel" [source]="./assoc.tests" [lineno]="28" [pid]="42134" )
declare -A wheat=([two]="b" [three]="c" [one]="a" [zero]="0" )
declare -A chaff=([one]="10" ["hello world"]="flip" [zero]="5" )
./assoc.tests: line 38: waste: readonly variable
./assoc.tests: line 39: unset: waste: cannot unset: readonly variable
./assoc.tests: line 40: chaff[*]: bad array subscript
./assoc.tests: line 41: [*]=12: invalid associative array key
declare -A chaff=([one]="a" ["hello world"]="flip" )
flip
argv[1] = <a>
argv[2] = <flip>
@@ -31,14 +32,14 @@ argv[2] = <flip>
argv[3] = <multiple>
argv[4] = <words>
argv[1] = <a flip multiple words>
./assoc.tests: line 57: declare: chaff: cannot destroy array variables in this way
./assoc.tests: line 59: chaff[*]: bad array subscript
./assoc.tests: line 60: [*]=12: invalid associative array key
declare -A wheat='([six]="6" ["foo bar"]="qux qix" )'
./assoc.tests: line 58: declare: chaff: cannot destroy array variables in this way
./assoc.tests: line 60: chaff[*]: bad array subscript
./assoc.tests: line 61: [*]=12: invalid associative array key
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" )'
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
argv[1] = <2>
argv[1] = <7>
argv[1] = <qux>
@@ -47,16 +48,16 @@ argv[3] = <blat>
argv[1] = <qux qix blat>
argv[1] = <16>
argv[1] = <16>
argv[1] = <flix>
argv[2] = <6>
argv[1] = <6>
argv[2] = <flix>
argv[1] = <six>
argv[2] = <foo>
argv[3] = <bar>
argv[1] = <six>
argv[2] = <foo bar>
8
/usr/local/bin . /bin /sbin /usr/sbin /usr/bin /bin /usr/ucb
bin . bin sbin sbin bin bin ucb
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
bin
/ / / / / / /
/
@@ -65,16 +66,16 @@ argv[1] = </>
argv[1] = <sbin>
argv[1] = </>
8
/usr/local/bin . /bin /sbin /usr/sbin /usr/bin /bin /usr/ucb
bin . bin sbin sbin bin bin ucb
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
/ / / / / / /
8
4 -- /bin
^usr^local^bin . ^bin ^sbin ^usr^sbin ^usr^bin ^bin ^usr^ucb
^usr^local^bin . ^bin ^sbin ^usr^sbin ^usr^bin ^bin ^usr^ucb
\usr/local/bin . \bin \sbin \usr/sbin \usr/bin \bin \usr/ucb
\usr\local\bin . \bin \sbin \usr\sbin \usr\bin \bin \usr\ucb
\usr\local\bin . \bin \sbin \usr\sbin \usr\bin \bin \usr\ucb
. ^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin ^bin ^usr^sbin
. ^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin ^bin ^usr^sbin
. \sbin \usr/bin \bin \usr/ucb \usr/local/bin \bin \usr/sbin
. \sbin \usr\bin \bin \usr\ucb \usr\local\bin \bin \usr\sbin
. \sbin \usr\bin \bin \usr\ucb \usr\local\bin \bin \usr\sbin
([a]=1)
qux foo
@@ -87,23 +88,23 @@ hits command
blat qux sh foo
/sbin/blat /usr/local/bin/qux /bin/sh /usr/sbin/foo
foo qux
argv[1] = </usr/sbin/foo>
argv[2] = </usr/local/bin/qux>
argv[3] = <-l>
qux foo
argv[1] = </usr/local/bin/qux>
argv[2] = <-l>
argv[3] = </usr/sbin/foo>
alias blat='cd /blat ; echo $PWD'
alias foo='/usr/sbin/foo'
alias qux='/usr/local/bin/qux -l'
alias sh='/bin/bash --login -o posix'
sh foo blat qux
argv[1] = </bin/bash --login -o posix>
argv[2] = </usr/sbin/foo>
argv[3] = <cd /blat ; echo $PWD>
argv[4] = </usr/local/bin/qux -l>
blat qux sh foo
argv[1] = <cd /blat ; echo $PWD>
argv[2] = </usr/local/bin/qux -l>
argv[3] = </bin/bash --login -o posix>
argv[4] = </usr/sbin/foo>
outside: outside
declare -A BASH_ALIASES='()'
declare -A BASH_CMDS='()'
declare -A afoo='([six]="six" ["foo bar"]="foo quux" )'
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A afoo=([six]="six" ["foo bar"]="foo quux" )
argv[1] = <inside:>
argv[2] = <six>
argv[3] = <foo quux>
@@ -137,56 +138,60 @@ abc
def
def
./assoc5.sub: line 13: declare: `myarray[foo[bar]=bleh': not a valid identifier
abc def bleh
myarray=(["a]a"]="abc" ["]"]="def" ["a]=test1;#a"]="123" [foo]="bleh" )
bleh abc def
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["]"]="def" )
123
myarray=(["a]a"]="abc" ["a]=test2;#a"]="def" ["]"]="def" ["a]=test1;#a"]="123" [foo]="bleh" )
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["a]=test2;#a"]="def" ["]"]="def" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
declare -A foo=(["bar\"bie"]="doll" )
bar'bie
doll
declare -A foo='(["bar'\''bie"]="doll" )'
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo='(["bar'\''bie"]="doll" )'
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo='(["bar'\''bie"]="doll" )'
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo='(["bar'\''bie"]="doll" )'
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo='(["bar'\''bie"]="doll" )'
declare -A foo=(["bar'bie"]="doll" )
bar$bie
doll
declare -A foo='(["bar\$bie"]="doll" )'
declare -A foo=(["bar\$bie"]="doll" )
bar[bie
doll
declare -A foo='(["bar[bie"]="doll" )'
declare -A foo=(["bar[bie"]="doll" )
bar`bie
doll
declare -A foo='(["bar\`bie"]="doll" )'
declare -A foo=(["bar\`bie"]="doll" )
bar\]bie
doll
declare -A foo='(["bar\\]bie"]="doll" )'
declare -A foo=(["bar\\]bie"]="doll" )
bar${foo}bie
doll
declare -A foo='(["bar\${foo}bie"]="doll" )'
declare -A foo=(["bar\${foo}bie"]="doll" )
bar
after printf
after use: 0
declare -A assoc=([0]="assoc" )
assoc
declare -A assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -Ar assoc=([two]="twoless" [three]="three" [one]="onemore" )
+21
View File
@@ -35,6 +35,7 @@ chaff[hello world]=flip
declare -p chaff
# TEST - errors
waste[stuff]=other
unset waste
chaff[*]=12
chaff=( [one]=a [*]=12 )
@@ -186,3 +187,23 @@ ${THIS_SH} ./assoc5.sub
${THIS_SH} ./assoc6.sub
${THIS_SH} ./assoc7.sub
# test converting between scalars and assoc arrays
unset assoc
assoc=assoc
declare -A assoc
declare -p assoc
echo ${assoc[@]}
# weird syntax required to append to multiple existing array elements using
# compound assignment syntax
unset assoc
declare -A assoc
assoc=( [one]=one [two]=two [three]=three )
assoc+=( [one]+=more [two]+=less )
declare -p assoc
readonly -A assoc
declare -p assoc
${THIS_SH} ./assoc8.sub
+7
View File
@@ -0,0 +1,7 @@
# warnings introduced beginning with bash-4.4-alpha
var=foo; declare -A "arr$var=([x]=y)"
key1=foo key2=bar
declare -A a=([foo]='([bar]=baz)') "b=${a[$key1]}"
+37
View File
@@ -0,0 +1,37 @@
after f1:declare -ar a=([0]="1")
./attr.tests: line 4: a: readonly variable
after f2:declare -ar a=([0]="1")
./attr.tests: line 5: a: readonly variable
after f3:declare -ar a=([0]="1")
./attr.tests: line 6: 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")
declare -r m="4"
in func:declare -r n="4"
declare -r n="4"
./attr1.sub: line 13: p: readonly variable
declare -r p="1"
./attr1.sub: line 19: r: readonly variable
declare -ar r=([0]="1")
./attr1.sub: line 23: r: readonly variable
declare -ar r=([0]="1")
./attr1.sub: line 27: r: readonly variable
declare -ar r=([0]="1")
./attr1.sub: line 31: readonly: r: readonly variable
declare -ar r=([0]="1")
declare -ar x=([0]="4")
in func:declare -ar y=([0]="4")
declare -ar y=([0]="4")
in func:declare -ar z=([0]="4")
declare -ar z=([0]="4")
in func:declare -ar y1=([0]="4")
declare -ar y1=([0]="4")
in func:declare -ar z1=([0]="4")
declare -ar z1=([0]="4")
declare -x p="4"
declare -ax r=([0]="4")
declare -ax r=([0]="(5)")
declare -ax r=([0]="6")
declare -ax r=([0]="7")
+41
View File
@@ -0,0 +1,41 @@
a=(outside)
f1() { readonly a=(1) ; }
f2() { readonly -a a=(2) ; }
f3() { readonly 'a=(3)' ; }
f4() { readonly -a 'a=(4)' ; }
f1
echo -n after f1:
declare -p a
f2
echo -n after f2:
declare -p a
f3
echo -n after f3:
declare -p a
f4
echo -n after f4:
declare -p a
b=(outside)
c=(outside)
d=(outside)
f2() { readonly -a b=(2) ; }
f3() { readonly 'c=(3)' ; }
f4() { readonly -a 'd=(4)' ; }
f2
echo -n after f2:
declare -p b
f3
echo -n after f3:
declare -p c
f4
echo -n after f4:
declare -p d
${THIS_SH} ./attr1.sub
${THIS_SH} ./attr2.sub
+55
View File
@@ -0,0 +1,55 @@
m=1
readonly m=4
declare -p m
n=1
f() { readonly n=4; echo -n in func: ; declare -p n ; }
f
declare -p n
p=1
readonly p
readonly p=4
declare -p p
r=(1)
readonly r
f() { readonly r=(4) ; }
f
declare -p r
f() { readonly r='(5)' ; }
f
declare -p r
f() { readonly -a r=(6) ; }
f
declare -p r
f() { readonly -a r='(7)' ; }
f
declare -p r
x=(1)
readonly x=(4)
declare -p x
y=(1)
f() { readonly y=(4); echo -n in func: ; declare -p y; }
f
declare -p y
z=(1)
f() { readonly -a z=(4); echo -n in func: ; declare -p z; }
f
declare -p z
f() { readonly y1=(4); echo -n in func: ; declare -p y1; }
f
declare -p y1
f() { readonly -a z1=(4); echo -n in func: ; declare -p z1; }
f
declare -p z1
+24
View File
@@ -0,0 +1,24 @@
p=1
export p
export p=4
declare -p p
r=(1)
export r
f() { export r=(4) ; }
f
declare -p r
f() { export r='(5)' ; }
f
declare -p r
f() { export -a r=(6) ; }
f
declare -p r
f() { export -a r='(7)' ; }
f
declare -p r
+76 -9
View File
@@ -158,14 +158,81 @@ b
before: f = 4
inside
after: f = 8 bar = 4
./builtins4.sub: line 2: declare: c: not found
./builtins4.sub: line 5: declare: d: not found
declare -a c='([0]="4")'
declare -A c='([0]="4" )'
declare -a c='([0]="1" [1]="2" [2]="3")'
declare -A c='([one]="1" [two]="2" [three]="3" )'
declare -a c='([0]="1" [1]="2" [2]="3")'
declare -a c='([0]="1" [1]="2" [2]="3")'
declare -a c
declare -A d
declare -a c=([0]="4")
declare -A c=([0]="4" )
declare -a c=([0]="1" [1]="2" [2]="3")
declare -A c=([two]="2" [three]="3" [one]="1" )
declare -a c=([0]="1" [1]="2" [2]="3")
declare -a c=([0]="1" [1]="2" [2]="3")
unset
unset
./builtins.tests: line 260: exit: status: numeric argument required
assoc 1 unset
array 1 unset
assoc 2 unset
array 2 unset
unset1
unset2
1
1
1
1
assoc A
array a
assoc B unset
array b unset
scalar 1
scalar 2
scalar 3 unset
argv[1] = <one two three>
assoc: 3
array: 3
scalar: 13
scalar: 1
scalar: 0
scalar: 1
scalar: 0
scalar: 0
all set:
one
two
f1 ()
{
echo f1
}
f2 ()
{
echo f2
}
all unset:
unset1
unset2
./builtins6.sub: line 28: declare: f1: not found
./builtins6.sub: line 28: declare: f2: not found
all reset:
one-one
two-one
f1 ()
{
echo f1
}
f2 ()
{
echo f2
}
vars unset:
unset1
unset2
f1 ()
{
echo f1
}
f2 ()
{
echo f2
}
funcs unset:
one-two
two-two
./builtins.tests: line 266: exit: status: numeric argument required
+6
View File
@@ -256,6 +256,12 @@ ${THIS_SH} ./builtins3.sub
# test behavior of using declare to create variables without assigning values
${THIS_SH} ./builtins4.sub
# test behavior of set and unset array variables
${THIS_SH} ./builtins5.sub
# test behavior of unset builtin with -f and -v options
${THIS_SH} ./builtins6.sub
# this must be last -- it is a fatal error
exit status
+61
View File
@@ -0,0 +1,61 @@
# a start at a test suite for what it means for an array to be set or unset and
# how to test that state
typeset -A A
A[a]=1
typeset -a a
a[1]=1
if [ -v A ]; then echo assoc 1; else echo assoc 1 unset; fi
if [ -v a ]; then echo array 1; else echo array 1 unset; fi
if [ -v "${A[@]}" ]; then echo assoc 2; else echo assoc 2 unset; fi
if [ -v "${a[@]}" ]; then echo array 2; else echo array 2 unset; fi
echo ${A-unset1}
echo ${a-unset2}
echo ${A[@]-unset3}
echo ${a[@]-unset4}
echo ${#A[@]}
echo ${#a[@]}
typeset -A B
typeset -a b
scalar1=foo
scalar2=
if [ -v A[@] ]; then echo assoc A; else echo assoc A unset; fi
if [ -v a[@] ]; then echo array a; else echo array a unset; fi
if [ -v B[@] ]; then echo assoc B; else echo assoc B unset; fi
if [ -v b[@] ]; then echo array b; else echo array b unset; fi
if [ -v scalar1[@] ]; then echo scalar 1; else echo scalar 1 unset; fi
if [ -v scalar2[@] ]; then echo scalar 2; else echo scalar 2 unset; fi
if [ -v scalar3[@] ]; then echo scalar 3; else echo scalar 3 unset; fi
unset a A
declare -A assoc=([one]=one [two]=two [three]=three)
declare -a array=(one two three)
scalar="one two three"
scalar2=
recho "${scalar[@]}"
echo assoc: ${#assoc[@]}
echo array: ${#array[@]}
echo scalar: ${#scalar}
echo scalar: ${#scalar[@]}
echo scalar: ${#scalar2}
echo scalar: ${#scalar2[@]}
echo scalar: ${#scalar3}
echo scalar: ${#scalar3[@]}
+68
View File
@@ -0,0 +1,68 @@
f1()
{
echo f1
}
f2()
{
echo f2
}
v1=one
v2=two
echo all set:
echo ${v1-unset1}
echo ${v2-unset2}
declare -f -p f1 f2
unset v1 f1 v2 f2
echo all unset:
echo ${v1-unset1}
echo ${v2-unset2}
declare -f -p f1 f2
f1()
{
echo f1
}
f2()
{
echo f2
}
v1=one-one
v2=two-one
echo all reset:
echo ${v1-unset1}
echo ${v2-unset2}
declare -f -p f1 f2
unset -v v1 f1 v2 f2
echo vars unset:
echo ${v1-unset1}
echo ${v2-unset2}
declare -f -p f1 f2
v1=one-two
v2=two-two
unset -f v1 f1 v2 f2
echo funcs unset:
echo ${v1-unset1}
echo ${v2-unset2}
declare -f f1 f2
+7
View File
@@ -7,6 +7,13 @@ no more clauses
1.0
./case.tests: line 29: xx: readonly variable
1.1
matches 1
no
no
no
no
no
ok
ok 1
ok 2
ok 3
+20
View File
@@ -29,5 +29,25 @@ readonly xx=1
case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac
echo ${xx}.$?
unset var empty
var=
case ']' in
[$var]*[$var]) echo matches 1;;
*) echo no match 1 ;;
esac
case abc in ( [] ) echo yes ;; ( * ) echo no ;; esac
empty=''
case abc in ( ["$empty"] ) echo yes ;; ( * ) echo no ;; esac
case abc in ( [] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
empty=''
case abc in ( ["$empty"] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
case abc in (["$empty"]|[!a-z]*) echo yes ;; (*) echo no ;; esac
case " " in ( [" "] ) echo ok;; ( * ) echo no;; esac
# tests of quote removal and pattern matching
${THIS_SH} ./case1.sub
+4
View File
@@ -43,3 +43,7 @@ Be Conservative in what you send and Liberal in what you accept
BE CONSERVATIVE IN WHAT YOU SEND AND LIBERAL IN WHAT YOU ACCEPT
Be conservative in what you send and liberal in what you accept
BE CONSERVATIVE IN WHAT YOU SEND AND LIBERAL IN WHAT YOU ACCEPT
AcknOwlEdgEmEnt acknOwlEdgEmEnt
oeNoPHiLe OEnOphIlE
abcdexyz
ABCDEXYZ
+14
View File
@@ -97,3 +97,17 @@ echo ${TEXT^^}
echo ${TEXT2^}
echo ${TEXT2^^}
M1=${S1^^[aeiou]}
M2=${U2,,[AEIOU]}
echo ${M1} ${M1~}
echo ${M2} ${M2~~}
declare -l lower=aBcDe
lower+=XyZ
echo $lower
declare -u upper=aBcDe
upper+=xYZ
echo $upper
+1
View File
@@ -71,3 +71,4 @@ swap32_posix ()
done
}
yes
ab cde
+13
View File
@@ -217,3 +217,16 @@ unset x
# fixed after bash-4.0 released
: $(case a in a) echo ;; # comment
esac)
# fixed after bash-4.3 released
testing=$(
echo test | while read line; do
case $line in
test) echo saw test ;;
*) echo other ;;
esac
done
)
# recommended to be parsed as a nested comsub instead of arithsub
echo $(( echo ab cde ) )
+21
View File
@@ -27,3 +27,24 @@ ok 3
ok 4
ok 5
ok 6
xyz
\/tmp\/foo\/bar
/tmp/foo/bar
/tmp/foo/bar
/tmp/foo/bar
1
2
3
4
5
6
5
6
a
b
c
a
b
c
1
2
+5
View File
@@ -41,4 +41,9 @@ bar'`
echo $(recho 'foo\
bar')
# long-standing parse error in all versions up through bash-4.3
echo ${foo:-$(echo a{b,c})} >/dev/null
${THIS_SH} ./comsub1.sub
${THIS_SH} ./comsub2.sub
${THIS_SH} ./comsub3.sub
+6
View File
@@ -46,3 +46,9 @@ esac)
echo $(case a in (a) echo ok 6 # comment
;;
esac)
echo $( # we just took and pasted in some
# code from another script inside a
# command substitution
echo xyz
)
+8
View File
@@ -0,0 +1,8 @@
qpath='\/tmp\/foo\/bar'
echo "$qpath"
# it's crazy that all three of these produce the same result
echo ${qpath//\\/}
echo ${qpath//"`echo \\`"/}
echo ${qpath//`echo "\\\\\\\\"`/}
+31
View File
@@ -0,0 +1,31 @@
x=$(
case 1 in
1) echo 1
esac
case 2 in
2) echo 2
esac
)
echo "$x"
x=$(case 1 in 1) echo 3;; esac; case 2 in 2) echo 4;; esac;)
echo "$x"
x=$(case 1 in 1) echo 5;; esac; case 2 in 2) echo 6;; esac)
echo "$x"
x=$(case 1 in 1) echo 5;; esac; case 2 in 2) echo 6;; esac; for f in a b c; do echo "$f" ; done)
echo "$x"
x=$(
for f in a b c; do
echo $f
done
case 1 in
1) echo 1
esac
case 2 in
2) echo 2
esac
)
echo "$x"
+5
View File
@@ -41,6 +41,11 @@ found 2
libc
ok 42
ok 43
ok 1
ok 2
ok 3
ok 4
ok 5
match 1
match 2
match 3
+11
View File
@@ -180,6 +180,17 @@ echo ${BASH_REMATCH[@]}
if [[ "123abc" == *?(a)bc ]]; then echo ok 42; else echo bad 42; fi
if [[ "123abc" == *?(a)bc ]]; then echo ok 43; else echo bad 43; fi
foo=""
[[ bar == *"${foo,,}"* ]] && echo ok 1
[[ bar == *${foo,,}* ]] && echo ok 2
shopt -s extquote
bs='\'
del=$'\177'
[[ bar == *$bs"$del"* ]] || echo ok 3
[[ "" == "$foo" ]] && echo ok 4
[[ "$del" == "${foo,,}" ]] || echo ok 5
${THIS_SH} ./cond-regexp1.sub
${THIS_SH} ./cond-regexp2.sub
+1 -4
View File
@@ -1,11 +1,8 @@
84575
63 60
a b c
84577
63 60
flop
./coproc.tests: line 22: 84577 Terminated coproc REFLECT { cat -; }
84579
coproc.tests: REFLECT: status 143
63 60
FOO
63 60
+25 -5
View File
@@ -1,6 +1,13 @@
: ${TMPDIR:=/tmp}
TMPOUT=${TMPDIR}/coproc-wait-$BASHPID
coproc { echo a b c; sleep 2; }
echo $COPROC_PID
case $COPROC_PID in
[0-9]*) ;;
*) echo COPROC_PID not integer ;;
esac
echo ${COPROC[@]}
read LINE <&${COPROC[0]}
@@ -10,7 +17,11 @@ wait $COPROC_PID
coproc REFLECT { cat - ; }
echo $REFLECT_PID
case $REFLECT_PID in
[0-9]*) ;;
*) echo REFLECT_PID not integer ;;
esac
echo ${REFLECT[@]}
echo flop >&${REFLECT[1]}
@@ -18,12 +29,21 @@ read LINE <&${REFLECT[0]}
echo $LINE
kill $REFLECT_PID
wait $REFLECT_PID
{ sleep 1; kill $REFLECT_PID; } &
wait $REFLECT_PID >$TMPOUT 2>&1 || echo "coproc.tests: REFLECT: status $?"
grep 'Terminated.*coproc.*REFLECT' < $TMPOUT >/dev/null 2>&1 || {
echo "coproc.tests: wait for REFLECT failed" >&2
}
rm -f $TMPOUT
exec 2>&1
coproc xcase -n -u
echo $COPROC_PID
case $COPROC_PID in
[0-9]*) ;;
*) echo COPROC_PID not integer ;;
esac
echo ${COPROC[@]}
echo foo >&${COPROC[1]}
+14
View File
@@ -211,6 +211,20 @@ esac
# arrays) -- bugs through bash 4.2
${THIS_SH} ./dollar-at-star1.sub
# more tests for expanding $@ and $* in a context where there is no word
# splitting
${THIS_SH} ./dollar-at-star2.sub
${THIS_SH} ./dollar-at-star3.sub
${THIS_SH} ./dollar-at-star4.sub
${THIS_SH} ./dollar-at-star5.sub
${THIS_SH} ./dollar-at-star6.sub
${THIS_SH} ./dollar-at-star7.sub
# tests for expansions of $@ and ${a[@]} (vs. $* and ${a[*]}) on the RHS of
# assignment statements with non-default IFS: $@ expands to args or array
# members separated by spaces
${THIS_SH} ./dollar-at-star8.sub
# tests for special expansion of "$*" and "${array[*]}" when used with other
# expansions -- bugs through bash-2.05b
${THIS_SH} ./dollar-star1.sub
+207
View File
@@ -0,0 +1,207 @@
OIFS="$IFS"
foo=' ,foo'
set -- "$foo"
if [[ $foo = ,* ]]; then echo bad 1; else echo ok 1; fi
if [[ $@ = ,* ]]; then echo bad 2; else echo ok 2; fi
if [[ $* = ,* ]]; then echo bad 3; else echo ok 3; fi
if [[ ${@} = ,* ]]; then echo bad 4; else echo ok 4; fi
if [[ ${*} = ,* ]]; then echo bad 5; else echo ok 5; fi
if [[ $1 = ,* ]]; then echo bad 6; else echo ok 6; fi
set -- ' ,foo'
if [[ $foo = ,* ]]; then echo bad 7; else echo ok 7; fi
if [[ $@ = ,* ]]; then echo bad 8; else echo ok 8; fi
if [[ $* = ,* ]]; then echo bad 9; else echo ok 9; fi
if [[ ${@} = ,* ]]; then echo bad 10; else echo ok 10; fi
if [[ ${*} = ,* ]]; then echo bad 11; else echo ok 11; fi
if [[ $1 = ,* ]]; then echo bad 12; else echo ok 12; fi
IFS=
if [[ $@ = ,* ]]; then echo bad 13; else echo ok 13; fi
if [[ $* = ,* ]]; then echo bad 14; else echo ok 14; fi
IFS="$OIFS"
foo=' ,foo'
set -- ' ' ',foo'
if [[ $@ = ,* ]]; then echo bad at 1; else echo ok at 1; fi
if [[ ${@} = ,* ]]; then echo bad at 2; else echo ok at 2; fi
if [[ $* = ,* ]]; then echo bad star 1; else echo ok star 1; fi
if [[ ${*} = ,* ]]; then echo bad star 2; else echo ok star 2; fi
foo=' ,foo'
set -- "$foo"
# expand_string_for_rhs
foo2=$@
echo "$foo2"
foo2=$*
echo "$foo2"
foo2="$@"
echo "$foo2"
foo2="$*"
echo "$foo2"
# expand_word_unsplit
case $@ in
$foo2) echo ok at 1 ;;
*) echo bad at 1 ;;
esac
# also uses expand_word_leave_quoted
case $@ in
$@) echo ok at 2;;
*) echo bad at 2;;
esac
case $@ in
$foo) echo ok at 3 ;;
*) echo bad at 3;;
esac
# expand_word_unsplit
case $* in
$foo2) echo ok star 1 ;;
*) echo bad star 1 ;;
esac
# also uses expand_word_leave_quoted
case $* in
$*) echo ok star 2;;
*) echo bad star 2;;
esac
case $* in
$foo) echo ok star 3 ;;
*) echo bad star 3;;
esac
case $@ in
$*) echo ok at-star 1;;
*) echo bad at-star 1;;
esac
case $* in
$@) echo ok at-star 2;;
*) echo bad at-star 2;;
esac
foo='a b c'
set -- $foo
# expand_string_for_rhs
IFS='|'
foo2=$@
echo "$foo2"
foo2=$*
echo "$foo2"
foo2="$@"
echo "$foo2"
foo2="$*"
echo "$foo2"
foo="a b c"
set -- $foo
if [[ $@ = $foo ]]; then echo ok at 1; else echo bad at 1; fi
if [[ $foo = $@ ]]; then echo ok at 2; else echo bad at 2; fi
case $@ in
$@) echo ok at 3 ;;
*) echo bad at 3 ;;
esac
case $@ in
$foo) echo ok at 4;;
*) echo bad at 4;;
esac
case $foo in
$@) echo ok at 5;;
*) echo bad at 5;;
esac
IFS="$OIFS"
foo="a b c"
set -- $foo
IFS=:
if [[ $@ = $foo ]]; then echo ok at 1; else echo bad at 1; fi
if [[ $foo = $@ ]]; then echo ok at 2; else echo bad at 2; fi
case $@ in
$@) echo ok at 3 ;;
*) echo bad at 3 ;;
esac
case $@ in
$foo) echo ok at 4;;
*) echo bad at 4;;
esac
case $foo in
$@) echo ok at 5;;
*) echo bad at 5;;
esac
IFS="$OIFS"
foo="a b c"
set -- $foo
IFS='|'
foo2=$@
case $@ in
$@) echo ok at 1 ;;
*) echo bad at 1 ;;
esac
case $foo2 in
$foo) echo ok at 2;;
*) echo bad at 2;;
esac
case $foo in
$foo2) echo ok at 3;;
*) echo bad at 3;;
esac
case $foo in
$foo) echo ok at 4;;
*) echo bad at 4;;
esac
case $foo2 in
$foo2) echo ok at 5;;
*) echo bad at 5;;
esac
case $foo2 in
$@) echo ok at 6;;
*) echo bad at 6;;
esac
case $@ in
$foo2) echo ok at 7;;
*) echo bad at 7;;
esac
case $foo in
$@) echo ok at 8;;
*) echo bad at 8;;
esac
case $@ in
$foo) echo ok at 9;;
*) echo bad at 9;;
esac
IFS="$OIFS"
+44
View File
@@ -0,0 +1,44 @@
unset f ; f=abcd
first_char=${f[@]:0:1}
recho $first_char
first_char=${f[0]:0:1}
recho $first_char
first_char=${f:0:1}
recho $first_char
first_char="${f[@]:0:1}"
recho $first_char
first_char="${f[@]:0:1}"
recho $first_char
first_char="${f[0]:0:1}"
recho $first_char
first_char="${f:0:1}"
recho $first_char
unset f;
f=( one two three )
first_word=${f[@]:0:1}
recho $first_word
first_word=${f[0]:0:1}
recho $first_word
first_word=${f:0:1}
recho $first_word
unset f;
f=( one two three )
first_word=${f[@]:0:1}
recho $first_word
set -- abc def ghi
printf '<%s> ' "123 $@ 456"; echo
printf '<%s> ' "123 $@\ 456"; echo
+97
View File
@@ -0,0 +1,97 @@
# tests for quoted and unquoted, split and unsplit expansions of $@ and $*
# Posix interpretation 221 speaks to this issue
set -- a b
IFS=
x=abc
printf "<%s>\n" ${x#$*}
a="a bc"
echo ${a#$*}
unset x a
a=$@
echo "$a"
a=$*
echo "$a"
printf '<%s>' $@ ; echo
IFS='
'
a=$@
echo "$a"
a=$*
echo "$a"
unset a
unset IFS
set a b "c d"
printf '<%s>' $* ; echo
IFS=
set a b "c d"
printf '<%s>' $* ; echo
IFS=:
set a b
printf '<%s>' ${foo=$*} ; echo
printf '<%s>' "${foo}" ; echo
unset foo
IFS='
'
printf '<%s>' ${foo=$@} ; echo
printf '<%s>' "$foo" ; echo
IFS=?
set a c
foo=abcd
echo ${foo#"$*"}
echo "${foo#$*}"
echo "${foo#'a?c'}"
echo "${foo#a?c}"
IFS=?
set a c
str=a$'\001'c
pat=a$'\001'
echo "${str#$pat}"
set a b
IFS=:
a=$@
recho "$a"
recho ${foo=$*}
recho "$foo"
unset foo
IFS='
'
recho ${foo=$@}
recho "$foo"
shift $#
unset foo x
set -- a b
x=abc
IFS=
printf "<%s>\n" ${x#$*}
printf "<%s>\n" "${x#$*}"
x=abcd
set a c
IFS='?'
printf "<%s>\n" ${x#$*}
printf "<%s>\n" "${x#$*}"
+53
View File
@@ -0,0 +1,53 @@
# testing various combinations of quoted and unquoted expansions of $@, and
# whether they generate empty words after expansion
n() { echo "$#"; }
n "$@"
n ${foo-"$@"}
n "${foo-$@}"
n ""$@
n """$@"
n $(true)$@
n "$(true)$@"
n "$(true)$@"
n "$(true)""$@"
n $xxx$@
n "$xxx$@"
n $xxx"$@"
n "$xxx""$@"
recho $xxx"$@"
echo after 1
recho "$xxx$@"
echo after 2
recho ${foo:-$xxx"$@"}
echo after 3
# this is where these things start to differ
echo same as 1
recho "${foo:-$xxx"$@"}"
echo same as 2
recho "${foo:-$xxx$@}"
echo null fields
recho ""$@
recho """$@"
echo null fields in rhs
echo null string with unquoted '$@'
recho ${foo:-""$@}
echo null string with quoted '$@'
recho ${foo:-"""$@"}
echo assignment
recho "${foo=$@}"
echo variable
recho "$foo"
echo dollar-at
recho "${@}"
+29
View File
@@ -0,0 +1,29 @@
OIFS="$IFS"
arr=(a b c)
recho ${arr[@]@Q}
recho "${arr[@]@Q}"
IFS="'"
recho ${arr[@]@Q}
recho "${arr[@]@Q}"
IFS="$OIFS"
arr=("'a'" "'b'" "'c'")
IFS="'"
recho ${arr[@]}
recho "${arr[@]}"
IFS="$OIFS"
IFS="'"
a="'a'"
recho $a
recho "$a"
IFS="$OIFS"
set -- "'a'" "'b'" "'c'"
IFS="'"
recho "${@}"
recho "$@"
+25
View File
@@ -0,0 +1,25 @@
IFS='' # testing with only empty IFS
set -- this is a test
printf '|%s|\n' ${1+"$@"}
echo
printf '|%s|\n' "${1+$@}"
echo
printf '|%s|\n' "$@"
echo
printf '|%s|\n' ${1-"$@"}
printf '|%s|\n' "${1-$@}"
echo
: ${foo:="$@"}
printf '|%s|\n' "$foo"
unset foo
: "${foo:=$@}"
printf '|%s|\n' "$foo"
unset foo
printf '|%s|\n' ${foo-"$@"}
printf '|%s|\n' "${foo-$@}"
+14
View File
@@ -0,0 +1,14 @@
function f {
typeset -a a
a=("$@")
typeset IFS=,
typeset a1="${a[@]} ${a[*]} $@ $* ${@} ${*}"
typeset a2=${a[@]}\ ${a[*]}\ $@\ $*\ ${@}\ ${*} a3 a4
a3="${a[@]} ${a[*]} $@ $* ${@} ${*}"
a4=${a[@]}\ ${a[*]}\ $@\ $*\ ${@}\ ${*}
unset -v IFS
printf '%s\n' "a1=$a1" "a2=$a2" "a3=$a3" "a4=$a4"
}
echo
f a b c
+199 -3
View File
@@ -103,6 +103,202 @@ var=${a[@]} ... one:::two three:::four
var="${a[@]}" ... one:::two three:::four
var=$@ ... one:::two three:::four
var="$@" ... one:::two three:::four
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
ok 11
ok 12
ok 13
ok 14
ok at 1
ok at 2
ok star 1
ok star 2
,foo
,foo
,foo
,foo
ok at 1
ok at 2
ok at 3
ok star 1
ok star 2
ok star 3
ok at-star 1
ok at-star 2
a b c
a|b|c
a b c
a|b|c
ok at 1
ok at 2
ok at 3
ok at 4
ok at 5
ok at 1
ok at 2
ok at 3
ok at 4
ok at 5
ok at 1
ok at 2
ok at 3
ok at 4
ok at 5
ok at 6
ok at 7
ok at 8
ok at 9
argv[1] = <a>
argv[1] = <a>
argv[1] = <a>
argv[1] = <a>
argv[1] = <a>
argv[1] = <a>
argv[1] = <a>
argv[1] = <one>
argv[1] = <o>
argv[1] = <o>
argv[1] = <one>
<123 abc> <def> <ghi 456>
<123 abc> <def> <ghi\ 456>
<c>
a bc
a b
ab
<a><b>
a b
a b
<a><b><c><d>
<a><b><c d>
<a><b>
<a:b>
<a><b>
<a b>
abcd
d
abcd
d
c
argv[1] = <a b>
argv[1] = <abcd>
argv[1] = <abcd>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a b>
<c>
<c>
<d>
<d>
0
0
1
1
1
0
0
0
1
0
0
0
1
after 1
after 2
after 3
same as 1
argv[1] = <>
same as 2
argv[1] = <>
null fields
argv[1] = <>
argv[1] = <>
null fields in rhs
null string with unquoted $@
argv[1] = <>
null string with quoted $@
assignment
argv[1] = <>
variable
argv[1] = <>
dollar-at
argv[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'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[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[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'c'>
argv[1] = <>
argv[2] = <a>
argv[1] = <'a'>
argv[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'c'>
argv[1] = <'a'>
argv[2] = <'b'>
argv[3] = <'c'>
|this|
|is|
|a|
|test|
|this|
|is|
|a|
|test|
|this|
|is|
|a|
|test|
|this|
|this|
|this is a test|
|this is a test|
|this|
|is|
|a|
|test|
|this|
|is|
|a|
|test|
a1=a b c a,b,c a b c a,b,c a b c a,b,c
a2=a b c a,b,c a b c a,b,c a b c a,b,c
a3=a b c a,b,c a b c a,b,c a b c a,b,c
a4=a b c a,b,c a b c a,b,c a b c a,b,c
xa|xb|xc
xa|xb|xc
a|b|c
@@ -222,17 +418,17 @@ third set:
"${@:2}a3 a2" a$1 #works as long as $1 and 3 are swapped
set y za3 a2 ax
0
declare -a a='([0]="y" [1]="za3 a2" [2]="ax")'
declare -a a=([0]="y" [1]="za3 a2" [2]="ax")
"${@:2}b$1 b2" b3 #fails! why?
set y zbx b2 b3
0
declare -a b='([0]="y" [1]="zbx b2" [2]="b3")'
declare -a b=([0]="y" [1]="zbx b2" [2]="b3")
${@:2}c$1 c2 c3 #works as long as quoting omitted
set y zcx c2 c3
0
declare -a c='([0]="y" [1]="zcx" [2]="c2" [3]="c3")'
declare -a c=([0]="y" [1]="zcx" [2]="c2" [3]="c3")
argv[1] = <>
argv[2] = <x>
argv[1] = <>
+25 -2
View File
@@ -35,7 +35,7 @@ hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
./errors.tests: line 106: hash: hashing disabled
./errors.tests: line 109: export: `AA[4]': not a valid identifier
./errors.tests: line 110: readonly: `AA[4]': not a valid identifier
./errors.tests: line 113: [-2]: bad array subscript
./errors.tests: line 113: unset: [-2]: bad array subscript
./errors.tests: line 117: AA: readonly variable
./errors.tests: line 121: AA: readonly variable
./errors.tests: line 129: shift: 5: shift count out of range
@@ -110,4 +110,27 @@ after f
./errors3.sub: line 5: no_such_file: No such file or directory
TEST
./errors3.sub: line 7: no_such_file: No such file or directory
./errors.tests: line 271: `!!': not a valid identifier
1
2
./errors4.sub: line 7: var: readonly variable
after readonly assignment
./errors4.sub: line 13: break: x: numeric argument required
1
2
./errors4.sub: line 7: var: readonly variable
./errors5.sub: line 6: array: unbound variable
./errors5.sub: line 7: array: unbound variable
./errors5.sub: line 10: 7: unbound variable
./errors5.sub: line 11: 7: unbound variable
after 1: 1
after 2: 1
after 3: 1
array after 1: 1
array after 2: 1
./errors6.sub: line 18: ${-3}: bad substitution
./errors6.sub: line 19: -3: bad substitution
after indir: 1
./errors6.sub: line 18: ${-3}: bad substitution
./errors6.sub: line 19: -3: bad substitution
after indir: 1
./errors.tests: line 278: `!!': not a valid identifier
+7
View File
@@ -262,6 +262,13 @@ echo $?
${THIS_SH} ./errors1.sub
${THIS_SH} ./errors2.sub
${THIS_SH} ./errors3.sub
${THIS_SH} ./errors4.sub
${THIS_SH} -o posix ./errors4.sub
${THIS_SH} ./errors5.sub
${THIS_SH} ./errors6.sub
THIS_SH="${THIS_SH} -o posix" ${THIS_SH} ./errors6.sub
# this must be last!
# in posix mode, a function name must be a valid identifier
+18
View File
@@ -0,0 +1,18 @@
# test effect of assigning to readonly vars on loops and non-interactive shells
# fatal error when in posix mode
var=foo
readonly var
for num in 1 2 3 4 5; do
if [ $num -eq 3 ]; then
var=bar
fi
echo $num
done
echo after readonly assignment
# non-numeric arguments to break are fatal errors for all non-interactive shells
for f in 1 2 3 4 5
do
break x
done
echo after loop
+11
View File
@@ -0,0 +1,11 @@
array[1]=one
array[2]=two
set -u
( echo ${#array} )
( echo ${array} )
set -- 1 2 3
( echo ${#7} )
( echo ${7} )
+20
View File
@@ -0,0 +1,20 @@
# problems with non-fatal expansion errors through bash-4.3
: ${THIS_SH:=./bash}
${THIS_SH} -c 'echo ${x!y} second
echo after 1: $?' 2>/dev/null
${THIS_SH} -c 'echo ${#+} second
echo after 2: $?' 2>/dev/null
${THIS_SH} -c 'echo ${#foo%} second
echo after 3: $?' 2>/dev/null
${THIS_SH} -c 'b[0]=4 ; echo ${b[ ]}
echo array after 1: $?' 2>/dev/null
${THIS_SH} -c 'typeset -A v ; v["0"]=one ; echo ${v[ ]}
echo array after 2: $?' 2>/dev/null
echo ${-3}
x=-3; echo ${!x}
echo after indir: $?
+45 -1
View File
@@ -13,7 +13,7 @@ after exec1.sub: one two three
126
./execscript: line 40: /: Is a directory
126
/: /: is a directory
/: /: Is a directory
126
./execscript: line 47: .: /: is a directory
1
@@ -60,4 +60,48 @@ expand_aliases on
0
0
0
/usr/local/bin:/usr/GNU/bin:/usr/bin:/bin:.
cannot find cat in $TMPDIR
cannot find cat with empty $PATH
PATH = /usr/local/bin:/usr/GNU/bin:/usr/bin:/bin:.
cannot find cat in $TMPDIR with hash
cannot find cat with empty $PATH with hash
PATH = /usr/local/bin:/usr/GNU/bin:/usr/bin:/bin:.
trap -- 'echo foo $BASH_SUBSHELL' EXIT
trap -- 'echo USR1 $BASHPID' SIGUSR1
between
trap -- 'echo foo $BASH_SUBSHELL' EXIT
trap -- 'echo USR1 $BASHPID' SIGUSR1
between 2
trap -- 'echo foo $BASH_SUBSHELL' EXIT
trap -- 'echo USR1 $BASHPID' SIGUSR1
in subshell: 1
in subshell pipeline: 1
group pipeline: 1
EXIT-group.1
foo 0
after
exit code: 1
exit code: 1
exit code: 1
exit code: 127
exit code: 127
exit code: 127
a
b
c
A
B
c
d
c
d
e
x1
x1a
x2
x2a
x2b
x3
x3a
x3b
+34
View File
@@ -0,0 +1,34 @@
# post bash-4.3 changes to how command -p works (avoid modifying $PATH)
: ${TMPDIR=/tmp}
xpath=/usr/local/bin:/usr/GNU/bin:/usr/bin:/bin:.
# set a value of PATH we can test for; versions of bash up to and including
# bash-4.3 would set $PATH while running command -p
PATH=$xpath
export PATH
command -p sh -c 'echo $PATH'
PATH=${TMPDIR}
command -pv cat >/dev/null || echo "cannot find cat using standard path"
command -p cat < /dev/null
#hash
PATH=$xpath
command -pv cat >/dev/null || echo "cannot find cat using xpath"
PATH=$TMPDIR command -pv cat >/dev/null || echo "cannot find cat using standard path with PATH=\$TMPDIR"
PATH= command -pv cat >/dev/null || echo "cannot find cat using standard path with empty \$PATH"
PATH=$TMPDIR command -v cat >/dev/null || echo "cannot find cat in \$TMPDIR"
PATH= command -v cat >/dev/null || echo "cannot find cat with empty \$PATH"
echo PATH = $PATH
hash cat
PATH=$xpath
PATH=$TMPDIR command -pv cat >/dev/null || echo "cannot find cat using stdpath with hash"
PATH= command -pv cat >/dev/null || echo "cannot find cat using stdpath with hash"
PATH=$TMPDIR command -v cat >/dev/null || echo "cannot find cat in \$TMPDIR with hash"
PATH= command -v cat >/dev/null || echo "cannot find cat with empty \$PATH with hash"
echo PATH = $PATH
+14
View File
@@ -0,0 +1,14 @@
trap 'echo USR1 $BASHPID' USR1
trap 'echo foo $BASH_SUBSHELL' 0
trap | cat
echo between
( trap )
echo between 2
{ trap; } | cat
( echo in subshell: $BASH_SUBSHELL )
( echo in subshell pipeline: $BASH_SUBSHELL ) | cat
{ echo group pipeline: $BASH_SUBSHELL;
trap 'echo EXIT-group.$BASH_SUBSHELL' EXIT; } | cat
+17
View File
@@ -0,0 +1,17 @@
: ${TMPDIR:=/var/tmp}
TMPFILE=$TMPDIR/exitcode
rm -f $TMPFILE
set -e
exit_handler() { echo "exit code: $?" ; touch $TMPFILE; }
false() { ! :; }
notfound() { nosuchcommand ; }
syntaxerror() { !:; }
main()
{(
trap exit_handler 0
"$@" >> /dev/null 2>&1
)}
main "$@"
echo "after main: should not get here"
+21
View File
@@ -0,0 +1,21 @@
echo x1 | ( cat & wait )
echo x1a | ( :& cat & wait )
echo x2 | for f in 1; do
cat & wait
done
echo x2a | if true; then cat & wait; fi
echo x2b | for (( i=0; i < 1; i++ )) ; do cat & wait; done
echo x3 | { cat & wait; }
lambda() { cat & wait; }
echo x3a | lambda
: ${TMPDIR:=/tmp}
SRCF=$TMPDIR/bash-src-$$
cat > $SRCF << \EOF
cat & wait
EOF
echo x3b | . $SRCF
rm -f $SRCF
+32
View File
@@ -112,6 +112,9 @@ ${THIS_SH} -i ./exec8.sub
${THIS_SH} ./exec9.sub
${THIS_SH} ./exec10.sub
${THIS_SH} ./exec11.sub
true | `echo true` &
echo after
@@ -125,3 +128,32 @@ ${THIS_SH} -c 'VAR=0; VAR=1 command exec; exit ${VAR}'
echo bad
) 2>/dev/null
[ $? = 127 ] || echo FAIL: bad exit status $? at $LINENO
unset FALSE
if [ -x /bin/false ]; then
FALSE=/bin/false
elif [ -x /usr/bin/false ]; then
FALSE=/usr/bin/false
else
FALSE='command false'
fi
# problem with undoing redirections before running exit trap through bash-4.3
${THIS_SH} ./exec12.sub false # function
${THIS_SH} ./exec12.sub command false
${THIS_SH} ./exec12.sub $FALSE
${THIS_SH} ./exec12.sub notfound
${THIS_SH} ./exec12.sub syntaxerror
${THIS_SH} ./exec12.sub nosuchcommand
# problem with fork optimization in bash-4.4-alpha
$THIS_SH -c 'echo a && /bin/echo b && echo c'
$THIS_SH -c 'echo A && /bin/echo B'
$THIS_SH -c '/bin/echo c && echo d'
$THIS_SH -c '/bin/echo c && /bin/echo d && echo e'
${THIS_SH} ./exec13.sub
+127
View File
@@ -4,6 +4,11 @@ argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^A>
argv[1] = <^?>
argv[1] = <bar>
argv[1] = <^A>
argv[1] = <^?>
argv[1] = <^A>
argv[1] = <^?>
argv[1] = <abcdefgh>
argv[1] = <abcdefgh>
argv[1] = <abcdefgh>
@@ -205,3 +210,125 @@ argv[1] = <correct>
argv[2] = <a>
argv[1] = <correct>
argv[2] = <a>
argv[1] = <^A>
argv[1] = <3>
argv[2] = <^C>
argv[3] = <^C>
argv[4] = <^C>
argv[1] = <^A>
argv[1] = <x^Ay^?z>
argv[1] = <x^Ay^?z>
declare -- var="xyz"
argv[1] = <declare>
argv[2] = <-->
argv[3] = <var="x^Ay^?z">
declare -- var="x\001y\177z"$
argv[1] = <$'x\001y\177z'>
argv[1] = <x^Ay^?z>
var=$'x\001y\177z'
./exp8.sub: line 16: xyz: syntax error: invalid arithmetic operator (error token is "z")
declare -a array=()
declare -a array=([0]=$'x\001y\177z')
argv[1] = <x^Ay^?z>
declare -a array=([0]=$'x\001y\177z')
declare -A array=([$'x\001y\177z']=$'a\242b\002c' )
abc
def
ghi
jkl
abc def ghi jkl
xxabc
def
ghi
jklyy
xxabc def ghi jklyy
abc
def
ghi
jkl
abc
def ghi
jkl
abc
def ghi
jkl
abc
def ghi
jkl
xxabc
def
ghi
jklyy
xxabc
def ghi
jklyy
abc
def
ghi
jklabc
def
ghi
jkl
abc
def ghi
jklabc
def ghi
jkl
abc:def ghi:jkl
abc:def ghi:jkl
abc:def ghi:jkl
abc
def ghi
jkl
abc:def ghi:jkl
abc:def ghi:jkl
abc
def ghi
jkl
var=abc:def ghi:jkl
abc:def ghi:jkl
var=abc:def ghi:jkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
var=abcdef ghijkl
abcdef ghijkl
var=abcdef ghijkl
abc
def ghi
jkl
abc def ghi jkl
abc def ghi jkl
abc def ghi jkl
abc
def
ghi
jkl
abc def ghi jkl
abc def ghi jkl
abc
def
ghi
jkl
var=abc def ghi jkl
abc def ghi jkl
var=abc def ghi jkl
abc
def ghi
jkl
[foo]
[]
[foo]
[]
[foo]
[foo]
[foo]
[]
[foo]
[]
[foo]
[]
+15
View File
@@ -31,6 +31,18 @@ recho `echo `
expect "<^?>"
recho `echo `
expect "bar"
recho ${foo:-"`echo bar`"}
expect "<^A>"
recho ${foo:-"`echo `"}
expect "<^?>"
recho ${foo:-"`echo `"}
expect "<^A>"
recho "`echo `"
expect "<^?>"
recho "`echo `"
# Test null strings without variable expansion
expect "<abcdefgh>"
recho abcd""efgh
@@ -390,3 +402,6 @@ ${THIS_SH} ./exp4.sub
${THIS_SH} ./exp5.sub
${THIS_SH} ./exp6.sub
${THIS_SH} ./exp7.sub
${THIS_SH} ./exp8.sub
${THIS_SH} ./exp9.sub
+11
View File
@@ -0,0 +1,11 @@
IFS=$'\001'
c=$'\001'
c2=$'\003'
IFS=$c # this is the problem line, IFS should end up being \001
recho "$IFS"
set -- $c2$c$c2$c$c2
recho $# "$1" "$2" "$3"
x=$c
recho "$x"
+31
View File
@@ -0,0 +1,31 @@
var=$'x\001y\177z'
recho "$var"
recho $var
declare -p var
recho $(declare -p var)
declare -p var | sed -n l
recho ${var@Q}
recho ${var@P}
echo ${var@A}
unset array
array=( [$'x\001y\177z']=foo ) # should be error
echo ${array[@]@A}
unset array
declare -a array=([0]=$'x\001y\177z')
declare -p array
unset array
array=( "$var" )
recho ${array[@]}
echo ${array[@]@A}
unset array
declare -A array
array=( [$'x\001y\177z']=$'a\242b\002c' )
echo ${array[@]@A}
+69
View File
@@ -0,0 +1,69 @@
# expansion test cases from Posix interp 888
set "abc" "def ghi" "jkl"
unset novar
IFS=' ' # a space
printf '%s\n' $*
printf '%s\n' "$*"
printf '%s\n' xx$*yy
printf '%s\n' "xx$*yy"
printf '%s\n' $@
printf '%s\n' "$@"
printf '%s\n' ${1+"$@"}
printf '%s\n' ${novar-"$@"}
printf '%s\n' xx$@yy
printf '%s\n' "xx$@yy"
printf '%s\n' $@$@
printf '%s\n' "$@$@"
IFS=':'
printf '%s\n' "$*"
var=$*; printf '%s\n' "$var"
var="$*"; printf '%s\n' "$var"
unset var
printf '%s\n' ${var-$*}
printf '%s\n' "${var-$*}"
printf '%s\n' ${var-"$*"}
printf '%s\n' ${var=$*}
printf 'var=%s\n' "$var"
unset var
printf '%s\n' "${var=$*}"
printf 'var=%s\n' "$var"
IFS='' # null
printf '%s\n' "$*"
var=$*; printf '%s\n' "$var"
var="$*"; printf '%s\n' "$var"
unset var
printf '%s\n' ${var-$*}
printf '%s\n' "${var-$*}"
printf '%s\n' ${var-"$*"}
printf '%s\n' ${var=$*}
printf 'var=%s\n' "$var"
unset var
printf '%s\n' "${var=$*}"
printf 'var=%s\n' "$var"
printf '%s\n' "$@"
unset IFS
printf '%s\n' "$*"
var=$*; printf '%s\n' "$var"
var="$*"; printf '%s\n' "$var"
unset var
printf '%s\n' ${var-$*}
printf '%s\n' "${var-$*}"
printf '%s\n' ${var-"$*"}
printf '%s\n' ${var=$*}
printf 'var=%s\n' "$var"
unset var
printf '%s\n' "${var=$*}"
printf 'var=%s\n' "$var"
printf '%s\n' "$@"
set --
printf '[%s]\n' foo "$*"
printf '[%s]\n' foo "$novar$*$(echo)"
printf '[%s]\n' foo $@
printf '[%s]\n' foo "$@"
printf '[%s]\n' foo ''$@
printf '[%s]\n' foo ''"$@"
printf '[%s]\n' foo ''"$novar$@$(echo)"
+14
View File
@@ -0,0 +1,14 @@
exportfunc ok 1
exportfunc ok 2
./exportfunc.tests: line 24: cve7169-bad: No such file or directory
./exportfunc.tests: eval: line 31: syntax error: unexpected end of file
./exportfunc.tests: line 30: cve7169-bad2: No such file or directory
./exportfunc1.sub: line 1: maximum here-document count exceeded
./exportfunc.tests: line 51: HELLO_WORLD: No such file or directory
eval ok
./exportfunc3.sub: line 10: export: foo=bar: cannot export
status: 1
equals-1
bad echo
./exportfunc3.sub: line 23: export: /bin/echo: cannot export
bar
+71
View File
@@ -0,0 +1,71 @@
# normal operation
foo()
{
echo exportfunc ok 1
}
export -f foo
${THIS_SH} -c foo
unset -f foo
foo-a ()
{
echo exportfunc ok 2
}
export -f foo-a
${THIS_SH} -c 'foo-a'
# CVE-2014-6271
env -i BASH_FUNC_foo%%='() { echo cve6271 ok; } ; echo BAD' ${THIS_SH} -c foo 2>/dev/null
# CVE-2014-7169
rm -f cve7169-bad
env -i BASH_FUNC_X%%='() { (a)=>\' ${THIS_SH} -c cve7169-bad 2>/dev/null
: < cve7169-bad
rm -f cve7169-bad
echo cve7169-bad2 > $TMPDIR/bar
rm -f cve7169-bad2
eval 'X() { (a)>\' ; . ./bar 2>/dev/null
: < cve7169-bad2
rm -f cve7169-bad2 $TMPDIR/bar
# CVE-2014-7186
${THIS_SH} ./exportfunc1.sub
# CVE-2014-7187
${THIS_SH} ./exportfunc2.sub
# CVE-2014-6277
env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<0 0" ${THIS_SH} -c foo 2>/dev/null
env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<`perl -e '{print "A"x100000}'` 0" ${THIS_SH} -c foo 2>/dev/null
${THIS_SH} -c "f(){ x(){ _;}; x(){ _;}<<a;}" 2>/dev/null
# CVE-2014-6278
env 'BASH_FUNC_FOO%%=() { 0;}>r[0${$(}0 {>"$(id >/dev/tty)"; }' ${THIS_SH} -c : 2>/dev/null
rm -f HELLO_WORLD
env BASH_FUNC_FOO%%='() { 0;}>r[0${$(}0 {>HELLO_WORLD; }' ${THIS_SH} -c : 2>/dev/null
: < HELLO_WORLD
env BASH_FUNC_x%%='() { _;}>_[$($())] { echo vuln;}' ${THIS_SH} -c : 2>/dev/null
env -i BASH_FUNC_x%%='() { _; } >_[${ $() }] { id; }' ${THIS_SH} -c : 2>/dev/null
env BASH_FUNC_x%%=$'() { _;}>_[$($())]\n{ echo vuln;}' ${THIS_SH} -c : 2>/dev/null
eval 'x() { _;}>_[$($())] { echo vuln;}' 2>/dev/null
eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }'
# other tests fixed in bash43-030 concerning function name transformation
env $'BASH_FUNC_\nfoo%%=() { echo transform-1; }' ${THIS_SH} -c foo 2>/dev/null
env $'BASH_FUNC_foo\n%%=() { echo transform-2; }' ${THIS_SH} -c foo 2>/dev/null
env $'BASH_FUNC_ foo %%=() { echo transform-3; }' ${THIS_SH} -c foo 2>/dev/null
unset -f foo
env $'BASH_FUNC_#badname%%'=$'() { :; }\nfoo () { echo transform-4; } ' ${THIS_SH} -c 'foo' 2>/dev/null
# tests of exported names
${THIS_SH} ./exportfunc3.sub
+21
View File
@@ -0,0 +1,21 @@
cat <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
EOF
echo after EOF
+400
View File
@@ -0,0 +1,400 @@
for x1 in ; do :
for x2 in ; do :
for x3 in ; do :
for x4 in ; do :
for x5 in ; do :
for x6 in ; do :
for x7 in ; do :
for x8 in ; do :
for x9 in ; do :
for x10 in ; do :
for x11 in ; do :
for x12 in ; do :
for x13 in ; do :
for x14 in ; do :
for x15 in ; do :
for x16 in ; do :
for x17 in ; do :
for x18 in ; do :
for x19 in ; do :
for x20 in ; do :
for x21 in ; do :
for x22 in ; do :
for x23 in ; do :
for x24 in ; do :
for x25 in ; do :
for x26 in ; do :
for x27 in ; do :
for x28 in ; do :
for x29 in ; do :
for x30 in ; do :
for x31 in ; do :
for x32 in ; do :
for x33 in ; do :
for x34 in ; do :
for x35 in ; do :
for x36 in ; do :
for x37 in ; do :
for x38 in ; do :
for x39 in ; do :
for x40 in ; do :
for x41 in ; do :
for x42 in ; do :
for x43 in ; do :
for x44 in ; do :
for x45 in ; do :
for x46 in ; do :
for x47 in ; do :
for x48 in ; do :
for x49 in ; do :
for x50 in ; do :
for x51 in ; do :
for x52 in ; do :
for x53 in ; do :
for x54 in ; do :
for x55 in ; do :
for x56 in ; do :
for x57 in ; do :
for x58 in ; do :
for x59 in ; do :
for x60 in ; do :
for x61 in ; do :
for x62 in ; do :
for x63 in ; do :
for x64 in ; do :
for x65 in ; do :
for x66 in ; do :
for x67 in ; do :
for x68 in ; do :
for x69 in ; do :
for x70 in ; do :
for x71 in ; do :
for x72 in ; do :
for x73 in ; do :
for x74 in ; do :
for x75 in ; do :
for x76 in ; do :
for x77 in ; do :
for x78 in ; do :
for x79 in ; do :
for x80 in ; do :
for x81 in ; do :
for x82 in ; do :
for x83 in ; do :
for x84 in ; do :
for x85 in ; do :
for x86 in ; do :
for x87 in ; do :
for x88 in ; do :
for x89 in ; do :
for x90 in ; do :
for x91 in ; do :
for x92 in ; do :
for x93 in ; do :
for x94 in ; do :
for x95 in ; do :
for x96 in ; do :
for x97 in ; do :
for x98 in ; do :
for x99 in ; do :
for x100 in ; do :
for x101 in ; do :
for x102 in ; do :
for x103 in ; do :
for x104 in ; do :
for x105 in ; do :
for x106 in ; do :
for x107 in ; do :
for x108 in ; do :
for x109 in ; do :
for x110 in ; do :
for x111 in ; do :
for x112 in ; do :
for x113 in ; do :
for x114 in ; do :
for x115 in ; do :
for x116 in ; do :
for x117 in ; do :
for x118 in ; do :
for x119 in ; do :
for x120 in ; do :
for x121 in ; do :
for x122 in ; do :
for x123 in ; do :
for x124 in ; do :
for x125 in ; do :
for x126 in ; do :
for x127 in ; do :
for x128 in ; do :
for x129 in ; do :
for x130 in ; do :
for x131 in ; do :
for x132 in ; do :
for x133 in ; do :
for x134 in ; do :
for x135 in ; do :
for x136 in ; do :
for x137 in ; do :
for x138 in ; do :
for x139 in ; do :
for x140 in ; do :
for x141 in ; do :
for x142 in ; do :
for x143 in ; do :
for x144 in ; do :
for x145 in ; do :
for x146 in ; do :
for x147 in ; do :
for x148 in ; do :
for x149 in ; do :
for x150 in ; do :
for x151 in ; do :
for x152 in ; do :
for x153 in ; do :
for x154 in ; do :
for x155 in ; do :
for x156 in ; do :
for x157 in ; do :
for x158 in ; do :
for x159 in ; do :
for x160 in ; do :
for x161 in ; do :
for x162 in ; do :
for x163 in ; do :
for x164 in ; do :
for x165 in ; do :
for x166 in ; do :
for x167 in ; do :
for x168 in ; do :
for x169 in ; do :
for x170 in ; do :
for x171 in ; do :
for x172 in ; do :
for x173 in ; do :
for x174 in ; do :
for x175 in ; do :
for x176 in ; do :
for x177 in ; do :
for x178 in ; do :
for x179 in ; do :
for x180 in ; do :
for x181 in ; do :
for x182 in ; do :
for x183 in ; do :
for x184 in ; do :
for x185 in ; do :
for x186 in ; do :
for x187 in ; do :
for x188 in ; do :
for x189 in ; do :
for x190 in ; do :
for x191 in ; do :
for x192 in ; do :
for x193 in ; do :
for x194 in ; do :
for x195 in ; do :
for x196 in ; do :
for x197 in ; do :
for x198 in ; do :
for x199 in ; do :
for x200 in ; do :
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
+25
View File
@@ -0,0 +1,25 @@
# test function names that cannot be exported
unset foo # remove from environment if necessary
function foo=bar
{
echo equals-1
}
export -f 'foo=bar'
echo status: $?
foo\=bar
printenv | grep 'foo=bar'
${THIS_SH} -c 'foo\=bar 2>/dev/null'
function /bin/echo
{
echo bad echo
}
/bin/echo foo
export -f '/bin/echo'
${THIS_SH} -c '/bin/echo bar'
+13
View File
@@ -92,3 +92,16 @@ a ab
a ab
a ab
a
. ..
. .. a.log
a.log
?(foo)
a.log
a.log
. ..
a.log
.x .y .z
a b c
.x .y .z a b c
a b c
a b c
+4
View File
@@ -370,4 +370,8 @@ ${THIS_SH} ./extglob1.sub
${THIS_SH} ./extglob1a.sub
${THIS_SH} ./extglob3.sub
${THIS_SH} ./extglob4.sub
exit 0
+7
View File
@@ -0,0 +1,7 @@
LANG=en_US.UTF-8
shopt -s extglob
a="aaaäöü"
echo "${a}" "${a//?aa}" "${a//\aaa}"
exit 0
+21
View File
@@ -0,0 +1,21 @@
shopt -s extglob
DIR=/tmp/extglob-$$
mkdir $DIR
cd $DIR
touch a.log
echo *(.)
echo *(.)*
echo ?(foo)*
echo ?(foo)
echo *(foo)*
echo @(|foo)*
echo *(foo).*
echo !(foo)*
cd $OLDPWD
rm -rf $DIR
+25
View File
@@ -0,0 +1,25 @@
LANG=C
LC_ALL=C
: ${TMPDIR:=/tmp}
GTDIR=$TMPDIR/extglob4-$$
shopt -s extglob
[ -d "${GTDIR}" ] || mkdir "${GTDIR}"
cd "${GTDIR}" || {
echo "extglob4: cannot cd to ${GTDIR}"
exit 2
}
touch a b c .x .y .z
echo .!(|.) # correct
echo * # correct
echo @(*|.!(|.)) # wrong, adds . and ..
echo @(*|@(f)) # ??
echo @(*|@(ff))
cd /
rm -rf $GTDIR
[[ a = a*?(/)b ]] && echo bad match 1
+12
View File
@@ -54,3 +54,15 @@ remaining args:
0
./getopts7.sub: line 4: getopts: `opt-var': not a valid identifier
remaining args:
opt: x
opt: y
opt: a
opt: b
opt: c
opt: z
$1 = a
./getopts10.sub: line 3: OPTARG: readonly variable
OPTARG = x = ?
unset x = ?
declare -r RO="foo"
declare -r RO="foo"
+5
View File
@@ -36,3 +36,8 @@ ${THIS_SH} ./getopts6.sub -ac
echo $? # this should be 2
${THIS_SH} ./getopts7.sub -a
${THIS_SH} ./getopts8.sub
${THIS_SH} ./getopts9.sub
${THIS_SH} ./getopts10.sub
+17
View File
@@ -0,0 +1,17 @@
set -- -a bb
readonly OPTARG
getopts :x x
echo OPTARG = $OPTARG x = $x
getopts x x
echo ${OPTARG-unset} x = $x
typeset -r RO=foo
typeset -n OPTARG=RO
getopts :x x
typeset -p RO
getopts x x
typeset -p RO
-1
View File
@@ -1,4 +1,3 @@
#!/local/bin/bash
#Time-stamp: <95/06/07 07:40:40 hrue@imf.unit.no>
getop () {
+13
View File
@@ -0,0 +1,13 @@
f()
{
typeset OPTIND=1
typeset opt
while getopts ":abcxyz" opt
do
echo opt: "$opt"
if [[ $opt = y ]]; then f -abc ; fi
done
}
f -xyz
+16
View File
@@ -0,0 +1,16 @@
f()
{
OPTIND=4
echo \$1 = $1
}
main()
{
while getopts abcdefg opt
do
f $opt
done
}
main -abc
-1
View File
@@ -582,4 +582,3 @@ bar/foo/e bar/foo/f foo/a foo/b
<b/b/a/a>
<b/b/a/b>
<b/b/b/a>
/tmp/empty
+9 -6
View File
@@ -1,3 +1,6 @@
olddir=$PWD
EMPTY=/tmp/empty
shopt -s globstar
s()
{
@@ -8,8 +11,8 @@ p()
printf '<%q>\n' "$@"
}
mkdir -p /tmp/empty/a/a/a
cd /tmp/empty
mkdir -p $EMPTY/a/a/a
cd $EMPTY
# good
p **
@@ -17,8 +20,8 @@ p **/**
p **/**/**
rm -rf a
mkdir -p /tmp/empty/{a,b}/{a,b}/{a,b}/{a,b}
cd /tmp/empty
mkdir -p $EMPTY/{a,b}/{a,b}/{a,b}/{a,b}
cd $EMPTY
# good
s '**/a'
@@ -76,5 +79,5 @@ p **/a/**/**/**
s '**/**/a/**'
p **/**/a/**
cd -
rm -rf /tmp/empty
cd "$olddir"
rm -rf $EMPTY
+6 -7
View File
@@ -59,13 +59,13 @@ qux
bar
qux
abc def geh
./heredoc3.sub: line 6: warning: here-document at line 4 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 9: warning: here-document at line 7 delimited by end-of-file (wanted `EOF')
= here is the text =
./heredoc3.sub: line 12: warning: here-document at line 10 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 15: warning: here-document at line 13 delimited by end-of-file (wanted `EOF')
this paren ) is not a problem
./heredoc3.sub: line 18: warning: here-document at line 16 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 21: warning: here-document at line 19 delimited by end-of-file (wanted `EOF')
these balanced parens ( ) are not a problem
./heredoc3.sub: line 24: warning: here-document at line 22 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 27: warning: here-document at line 25 delimited by end-of-file (wanted `EOF')
quoted balanced parens \( ) are not a problem either
more text in a subshell
some more text in a different subshell
@@ -76,15 +76,14 @@ ENDEND
end ENDEND
hello
end hello
x star x
end x*x
helloEND
end helloEND
hello
\END
end hello<NL>\END
./heredoc3.sub: line 74: warning: here-document at line 72 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 75: syntax error: unexpected end of file
./heredoc3.sub: line 78: warning: here-document at line 76 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 79: syntax error: unexpected end of file
comsub here-string
./heredoc.tests: line 105: warning: here-document at line 103 delimited by end-of-file (wanted `EOF')
hi
+5 -1
View File
@@ -1,3 +1,6 @@
SAVEPWD=$PWD
cd $TMPDIR || echo "heredoc3.sub: cannot cd to $TMPDIR" >&2
text=$(cat <<EOF
here is the text
EOF)
@@ -49,9 +52,10 @@ hello
END
echo end hello
cat <<x*x & touch 'x*x'
cat <<x*x >/dev/null & touch 'x*x'
x star x
x*x
wait $!
echo end 'x*x'
rm 'x*x'
+5 -2
View File
@@ -24,5 +24,8 @@ f3 ()
echo $(echo hi)
echo ho
echo off to work we go
declare -a uu='([0]="" [1]="kghfjk" [2]="jkfzuk" [3]="i
")'
declare -a uu=([0]="" [1]="kghfjk" [2]="jkfzuk" [3]=$'i\n')
foo bar
foo bar
qux:::::bax
qux:::::bax
+2
View File
@@ -37,3 +37,5 @@ cat <<< "echo $(echo off to work we go)"
IFS="/" read -r -d $'\000' -a uu <<< /kghfjk/jkfzuk/i
declare -p uu
${THIS_SH} ./herestr1.sub
+10
View File
@@ -0,0 +1,10 @@
# problems with word splitting unquoted here-strings present since bash-3.2
x="foo bar"
cat <<< $x # Word-splitting appears to collapse the run of whitespace
cat <<< "$x" # Whitespace preserved, as with here doc
x="qux:::::bax"
IFS=':'
cat <<< $x # Word-splitting appears to collapse the run of whitespace
cat <<< "$x" # Whitespace preserved, as with here doc
+67
View File
@@ -127,3 +127,70 @@ echo '!!' \!\!
ok 1
ok 2
ok 3
echo shopt a
shopt a
echo a b c d 2> /dev/null
a b c d
one two three four
echo two ; echo four
one two three four
echo four ; echo two
!
!
!
!
!
!
!
!
!
\!
\!
\!
\!
a
b
c
echo "#!/bin/bash" set -o posix
#!/bin/bash set -o posix
!!
!!
a
echo $(echo echo a)
echo a
a
echo echo a $(echo echo a)
echo a echo a
b
!! $(echo !!)
c
echo "echo c" "$(echo echo c)"
echo c echo c
d
echo "echo d" $(echo "echo d")
echo d echo d
e
!! !!
f
!!
f
!!
g
echo "echo g"
echo g
g
eval echo "echo g"
echo g
a
cat < <(echo echo a)
echo a
b
echo echo b `echo echo b`
echo b echo b
c
!
d
!
e
! !
./histexp4.sub: line 20: !': event not found
+18
View File
@@ -122,3 +122,21 @@ echo ${!var2}
# Bash-2.01[.1] fails this test -- it attempts history expansion after the
# history_comment_char
echo ok 3 # !1200
# bash versions through bash-4.3 fail this; they make the digit preceding the
# > into a separate word, changing the meaning of the redirection
shopt a b c d 2>/dev/null
echo !shopt-1
echo !shopt*
# make sure a :p modifier anywhere on the line affects all history expansions
echo one two three four
echo !:2:p ; echo !$
echo one two three four
echo !$ ; echo !:2:p
${THIS_SH} ./histexp1.sub
${THIS_SH} ./histexp2.sub
${THIS_SH} ./histexp3.sub
${THIS_SH} ./histexp4.sub
+23
View File
@@ -0,0 +1,23 @@
LC_ALL=C
LANG=C
set -o history
set -H
echo '!'
echo "!"
echo !
echo "$( echo '!' )"
echo "$( echo "!" )"
echo "$( echo ! )"
echo $( echo '!' )
echo $( echo "!" )
echo $( echo ! )
echo "$( echo "\!" )"
echo "\!"
echo "$( echo '\!' )"
echo '\!'
+14
View File
@@ -0,0 +1,14 @@
LANG=C LC_ALL=C
set -o history
echo a
echo b
echo c
set -o histexpand
set -o posix
echo "#!/bin/bash" !!
echo '!!'
echo "!!"
+35
View File
@@ -0,0 +1,35 @@
HISTFILE=${TMPDIR}/bashhist-$$
set -o history
set -o histexpand
echo a
echo $(echo !!)
echo a
echo !! $(echo !!)
echo b
echo '!!' '$(echo !!)'
echo c
echo "!!" "$(echo !!)"
echo d
echo "!!" $(echo "!!")
echo e
echo '!!' $(echo '!!')
echo f
echo '!!'
echo f
eval echo '!!'
echo g
echo "!!"
echo g
eval echo "!!"
set +o history
rm -f $HISTFILE # just in case
+23
View File
@@ -0,0 +1,23 @@
HISTFILE=$TMPDIR/bashhist-$$
set -o history
set -o histexpand
echo a
cat < <(echo !!)
echo b
echo !! `echo !!`
echo c
echo "$(echo "!" )"
echo d
echo "$(echo '!' )"
echo e
echo '!' "!"
echo "'!'"
set +o history
rm -f $HISTFILE
+2 -2
View File
@@ -140,7 +140,7 @@ three
one
two
three
4.3
4.4
echo ${BASH_VERSION%\.*}
4.3
4.4
echo ${BASH_VERSION%\.*}
+1 -1
View File
@@ -109,6 +109,6 @@ shopt -q -o history
echo $?
${THIS_SH} ./history1.sub
rm foohist-*
rm -f $TMPDIR/foohist-*
${THIS_SH} ./history2.sub
+1 -1
View File
@@ -1,6 +1,6 @@
trap 'rm -f $HISTFILE' 0 1 2 3 6 15
HISTFILE=foohist-$$
HISTFILE=$TMPDIR/foohist-$$
unset HISTIGNORE HISTCONTROL
set -o history
+21 -16
View File
@@ -17,35 +17,40 @@ aéb
1.0000
1.0000
1,0000
1
bytematch
0000000 254 012
0000002
Passed all 1378 Unicode tests
0000000 303 277 012
0000000 303 277 012
0000003
0000000 303 277 012
0000000 303 277 012
0000003
0000000 303 277 012
0000000 303 277 012
0000003
0000000 303 277 012
0000000 303 277 012
0000003
0000000 357 277 277 012
0000000 357 277 277 012
0000004
0000000 357 277 277 012
0000000 357 277 277 012
0000004
0000000 012
0000000 012
0000001
0000000 012
0000000 012
0000001
0000000 012
0000000 012
0000001
0000000 012
0000000 012
0000001
0000000 303 277 012
0000000 303 277 012
0000003
0000000 303 277 012
0000000 303 277 012
0000003
0000000 303 277 012
0000000 303 277 012
0000003
0000000 101 040 302 243 040 305 222 012
0000000 101 040 302 243 040 305 222 012
0000010
./unicode3.sub: line 2: 5作3+齷8叚窸: command not found
5作3+齷8叚窸
./unicode3.sub: line 3: $'5\247@3\231+\306S8\237\242\352\263': command not found
./unicode3.sub: line 5: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory
$'5\247@3\231+\306S8\237\242\352\263'
+ : $'5\247@3\231+\306S8\237\242\352\263'
+7 -2
View File
@@ -35,8 +35,10 @@ esac
set a b
printf '%s\n' "$*"
# squeeze out blanks to avoid white space differences in od implementations
printf '%s' "$*" | od -b | ( IFS=$' \t\n' ; while read line; do echo $line; done; )
. ./test-glue-functions
printf '%s' "$*" | od -b | _intl_normalize_spaces
# display differences make this problematic
${THIS_SH} ./intl1.sub
@@ -44,6 +46,9 @@ ${THIS_SH} ./intl1.sub
# this tests both international handling in printf and temporary environments
${THIS_SH} ./intl2.sub
# test splitting on characters instead of bytes
${THIS_SH} ./intl3.sub
${THIS_SH} ./unicode1.sub 2>/dev/null
${THIS_SH} ./unicode2.sub
+23
View File
@@ -0,0 +1,23 @@
. ./test-glue-functions
# more tests to make sure that IFS splits on characters, not bytes
export LANG=en_US.UTF-8
euro=$'\342\202\254'
o342=$'\342'
o202=$'\202'
o254=$'\254'
IFS=$o254
t=+$euro+
set -- $t
echo "$#"
# but matching still occurs on bytes if we don't have a valid multibyte char
case $euro in
*$o202*) echo bytematch ;;
*) echo mbchar match ;;
esac
echo "${euro##*$o202}" | od -b | _intl_normalize_spaces

Some files were not shown because too many files have changed in this diff Show More