bash-5.0 distribution sources and documentation

This commit is contained in:
Chet Ramey
2019-01-07 09:27:52 -05:00
parent 6444760999
commit d233b485e8
528 changed files with 84836 additions and 67099 deletions
+12
View File
@@ -18,3 +18,15 @@ one
two
three
four
Error: bar
ok 1
ok 2
text
whoops: nullalias
foo
a
a b
a b
a a b
ok 3
ok 4
+2
View File
@@ -38,3 +38,5 @@ unalias foo bar baz
${THIS_SH} ./alias1.sub
${THIS_SH} ./alias2.sub
${THIS_SH} ./alias3.sub
${THIS_SH} ./alias4.sub
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
shopt -s expand_aliases
alias foo='oneword'
foo_word='foo'
#
# Fails silently to match 'foo':
#
case "$foo_word"
in
foo) ;;
*) echo bad 1;;
esac
+70
View File
@@ -0,0 +1,70 @@
shopt -s expand_aliases
# from an austin-group report
alias foo="echo 'Error:"
foo bar'
# from some FreeBSD sh tests
v=1
alias a='unalias -a
v=2'
eval a
[ "$v" = 2 ] && echo ok 1
v=1
alias a='unalias a
v=2'
eval a
[ "$v" = 2 ] && echo ok 2
# make sure command doesn't ever reset anything even if it's made a keyword
unalias -a
alias command=command
alias true='echo bad'
eval 'command true'
unalias -a
alias alias0=command
alias true='echo bad'
eval 'alias0 true'
# make sure null aliases are ok
unalias -a
alias nullalias=''
alias foo='echo '
foo nullalias text
unalias foo
# aliases shouldn't be expanded in quoted strings even when the previous word
# is an alias whose expansion ends in a space
alias foo="echo 'whoops: "
foo nullalias'
unalias -a
# recursive alias definitions
alias echo=echo
eval echo foo
alias echo='echo a'
echo
echo b
eval echo b
echo $(eval echo b)
unalias -a
# alias expansion when in a command position after redirections
alias e=echo
eval '</dev/null e ok 3'
eval 'a=true e ok 4'
alias comment=#
comment
alias long_comment='# for x in '
long_comment text after
# comment
comment foo bar
+4 -4
View File
@@ -64,11 +64,11 @@ fx ()
0
1
2
./arith-for.tests: line 77: syntax error: arithmetic expression required
./arith-for.tests: line 77: syntax error: `(( i=0; "i < 3" ))'
bash: -c: line 0: syntax error: arithmetic expression required
bash: -c: line 0: syntax error: `(( i=0; "i < 3" ))'
2
./arith-for.tests: line 83: syntax error: `;' unexpected
./arith-for.tests: line 83: syntax error: `(( i=0; i < 3; i++; 7 ))'
bash: -c: line 0: syntax error: `;' unexpected
bash: -c: line 0: syntax error: `(( i=0; i < 3; i++; 7 ))'
2
20
20
+8 -6
View File
@@ -74,17 +74,19 @@ type fx
fx
# errors
for (( i=0; "i < 3" ))
{
${THIS_SH} -c 'for (( i=0; "i < 3" ))
do
echo $i
done
echo $?
done' ; echo $? ; } 2>&1 | sed 's|^.*/||'
#echo $?
for (( i=0; i < 3; i++; 7 ))
{
${THIS_SH} -c 'for (( i=0; i < 3; i++; 7 ))
do
echo $i
done
echo $?
done' ; echo $?; } 2>&1 | sed 's|^.*/||'
#echo $?
# one-liners added in post-bash-2.04
for ((i=0; i < 20; i++)) do : ; done
+12 -4
View File
@@ -242,14 +242,22 @@ efg
e
abcdefg
efg
0
0
0
0
0
0
0
8 12
./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")
./arith.tests: line 297: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
./arith.tests: line 301: a b: syntax error in expression (error token is "b")
./arith.tests: line 302: ((: a b: syntax error in expression (error token is "b")
42
42
42
42
42
42
./arith.tests: line 310: b[c]d: syntax error in expression (error token is "d")
./arith.tests: line 314: 'foo' : syntax error: operand expected (error token is "'foo' ")
./arith.tests: line 318: b[c]d: syntax error in expression (error token is "d")
+8
View File
@@ -283,6 +283,9 @@ ${THIS_SH} ./arith6.sub
# part of word expansions such as substring extraction
${THIS_SH} ./arith7.sub
# problems with evaluation of conditional expressions
${THIS_SH} ./arith8.sub
x=4
y=7
@@ -306,5 +309,10 @@ printf "%u\n" $n
echo $(( 16#$(printf "%x\n" $n) ))
echo $(( 16#$(printf "%X\n" $n) ))
# these are errors
foo=1
echo $(( 'foo' ))
# causes longjmp botches through bash-2.05b
a[b[c]d]=e
+37
View File
@@ -0,0 +1,37 @@
# problems with evaluation of wrong terms in conditional expressions through
# bash-4.4
a=0 x="a=1"
((0?x:0))
echo $a
unset a x
a=0 x="a=1"
((1?0:x))
echo $a
unset a x
a=0 x="a=1"
((0?(x):0))
echo $a
unset a x
a=0 x="a=1"
((0?$x:0))
echo $a
unset a x
a=0 x="a=1"
((0&&x))
echo $a
unset a x
a=0 x="a=1"
((1||x))
echo $a
unset a x
a=0
((0?arr[a=1]:0))
echo $a
unset a
+280 -20
View File
@@ -26,7 +26,7 @@ hello world
11
3
bdef hello world test expression test 2
./array.tests: line 76: readonly: `a[5]': not a valid identifier
./array.tests: line 79: 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")
@@ -46,17 +46,17 @@ 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
./array.tests: line 104: ${b[ ]}: bad substitution
./array.tests: line 106: c[-2]: bad array subscript
./array.tests: line 107: c: bad array subscript
./array.tests: line 103: a: readonly variable
./array.tests: line 105: b[]: bad array subscript
./array.tests: line 106: b[*]: bad array subscript
this
./array.tests: line 109: c[-2]: bad array subscript
./array.tests: line 110: c: bad array subscript
./array.tests: line 109: d[7]: cannot assign list to array member
./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
./array.tests: line 112: d[7]: cannot assign list to array member
./array.tests: line 114: []=abcde: bad array subscript
./array.tests: line 114: [*]=last: cannot assign to non-numeric index
./array.tests: line 114: [-65]=negative: bad array subscript
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
@@ -68,8 +68,8 @@ 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
./array.tests: line 122: unset: ps1: not an array variable
./array.tests: line 126: declare: c: cannot destroy array variables in this way
this of
this is a test of read using arrays
this test
@@ -127,7 +127,7 @@ grep [ 123 ] *
6 7 9 5
length = 3
value = new1 new2 new3
./array.tests: line 239: narray: unbound variable
./array.tests: line 242: narray: unbound variable
./array1.sub: line 1: syntax error near unexpected token `('
./array1.sub: line 1: `printf "%s\n" -a a=(a 'b c')'
./array2.sub: line 1: declare: `[]=asdf': not a valid identifier
@@ -154,10 +154,10 @@ for case if then else
12 14 16 18 20
4414758999202
aaa bbb
./array.tests: line 289: syntax error near unexpected token `<>'
./array.tests: line 289: `metas=( <> < > ! )'
./array.tests: line 290: syntax error near unexpected token `<>'
./array.tests: line 290: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
./array.tests: line 292: syntax error near unexpected token `<>'
./array.tests: line 292: `metas=( <> < > ! )'
./array.tests: line 293: syntax error near unexpected token `<>'
./array.tests: line 293: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
abc 3
case 4
abc case if then else 5
@@ -395,7 +395,7 @@ qux: unset array element 0: ok
0
0
1
2
./array17.sub: line 30: ~: syntax error: operand expected (error token is "~")
0
0
3
@@ -446,7 +446,7 @@ declare -a a=([0]="1" [1]="2" [2]="3")
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 a=([1]="b" [0]="a" )
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]")
@@ -502,3 +502,263 @@ unset
declare -a a=()
declare -A A=()
declare -a foo=([0]="1" [1]="(4 5 6)" [2]="3")
a1
argv[1] = <>
argv[2] = <>
a2
argv[1] = <y>
argv[1] = <z>
a3
argv[1] = <>
argv[2] = <x>
a4
argv[1] = <y>
p1
argv[1] = <>
argv[2] = <>
p2
argv[1] = <>
argv[2] = <x>
p3
argv[1] = <y>
<X> <X> <X> <X>
<X> <X> <X> <X>
./array23.sub: line 9: $( echo >&2 foo ) : syntax error: operand expected (error token is "$( echo >&2 foo ) ")
./array23.sub: line 10: $( echo >&2 foo ) : syntax error: operand expected (error token is "$( echo >&2 foo ) ")
foo
0
foo
foo
foo
6
./array23.sub: line 21: $( echo >&2 foo ): syntax error: operand expected (error token is "$( echo >&2 foo )")
./array23.sub: line 22: $( echo >&2 foo ): syntax error: operand expected (error token is "$( echo >&2 foo )")
0
0
0
IFS=: ${var-$*}
abc
def ghi
jkl
abc
def ghi
jkl
----
IFS=: ${var=$*}
abc
def ghi
jkl
var=abc:def ghi:jkl
abc
def ghi
jkl
var=abc:def ghi:jkl
----
IFS=: ${var+$*}
abc
def ghi
jkl
abc
def ghi
jkl
----
IFS= ${var-$*}
abc
def ghi
jkl
abc
def ghi
jkl
----
IFS= ${var=$*}
abcdef ghijkl
var=abcdef ghijkl
abcdef ghijkl
var=abcdef ghijkl
----
IFS= ${var+$*}
abc
def ghi
jkl
abc
def ghi
jkl
1. indexed:
reference:
1. 0
./array25.sub: line 11: ' ': syntax error: operand expected (error token is "' '")
3. 0
4. 0
5. 0
6. 0
assignment:
1.declare -a a=([0]="10" [1]="1")
2.declare -a a=([0]="11" [1]="1")
3.declare -a a=([0]="12" [1]="1")
4.declare -a a=([0]="13" [1]="1")
arithmetic:
1.declare -a a=([0]="10" [1]="1")
2.declare -a a=([0]="11" [1]="1")
3.declare -a a=([0]="12" [1]="1")
4.declare -a a=([0]="13" [1]="1")
5.declare -a a=([0]="10" [1]="1")
6.declare -a a=([0]="11" [1]="1")
7.declare -a a=([0]="12" [1]="1")
8.declare -a a=([0]="13" [1]="1")
2. associative:
reference:
1.
2.
3.
4.
5.
6.
assignment:
1.declare -A a=([1]="1" [0]="0" [" "]="10" )
2.declare -A a=([1]="1" [0]="0" [" "]="11" )
3.declare -A a=([1]="1" [0]="0" [" "]="12" )
4.declare -A a=([1]="1" [0]="0" [" "]="13" )
arithmetic:
1.declare -A a=([1]="1" [0]="0" [" "]="10" )
2.declare -A a=([1]="1" [0]="0" [" "]="11" )
3.declare -A a=([1]="1" [0]="0" [" "]="12" )
4.declare -A a=([1]="1" [0]="0" [" "]="13" )
5.declare -A a=([1]="1" [0]="0" [" "]="10" )
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" )
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa+bb>
argv[1] = <xa+bb>
argv[1] = <xa+bb>
argv[2] = <xa+bb>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bb+xa>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xabb>
argv[1] = <xabb>
argv[1] = <xabb>
argv[2] = <xabb>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bb>
argv[2] = <xa>
argv[1] = <bbxa>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <bb>
argv[2] = <aa>
argv[1] = <bb>
argv[2] = <aa>
argv[1] = <bb>
argv[2] = <aa>
argv[1] = <bb+aa>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[3] = <a>
argv[4] = <b>
argv[1] = <a+b>
argv[2] = <a+b>
argv[1] = <a>
argv[2] = <b>
argv[3] = <a>
argv[4] = <b>
argv[1] = <b>
argv[2] = <a>
argv[1] = <b>
argv[2] = <a>
argv[1] = <b>
argv[2] = <a>
argv[1] = <b+a>
7
./array27.sub: line 11: a[]]=7 : syntax error: invalid arithmetic operator (error token is "]=7 ")
declare -A A=([$'\t']="2" [" "]="2" )
./array27.sub: line 23: ((: A[]]=2 : syntax error: invalid arithmetic operator (error token is "]=2 ")
declare -A A=([$'\t']="2" ["*"]="2" [" "]="2" ["@"]="2" )
./array27.sub: line 32: A[]]: bad array subscript
declare -A A=([$'\t']="X" ["*"]="X" [" "]="X" ["@"]="X" )
./array27.sub: line 40: A[]]: bad array subscript
declare -A A=([$'\t']="X" ["*"]="X" [" "]="X" ["@"]="X" )
./array27.sub: line 48: declare: `A[]]=X': not a valid identifier
declare -A A=(["*"]="X" ["@"]="X" )
./array27.sub: line 56: declare: `A[]]=X': not a valid identifier
./array27.sub: line 56: A[*]: bad array subscript
./array27.sub: line 56: A[@]: bad array subscript
declare -A A
+10 -1
View File
@@ -21,6 +21,9 @@ unset a
a=abcde
declare -a a
echo ${a[0]}
if [ "$a" != "${a[0]}" ]; then
echo 'array.tests: $a and $a[0] array mismatch'
fi
unset a
a=abcde
@@ -248,7 +251,7 @@ ${THIS_SH} ./array3.sub
${THIS_SH} ./array4.sub
set +u
cd /tmp
cd ${TMPDIR:=/tmp}
touch 1=bar
foo=([10]="bar")
@@ -397,3 +400,9 @@ ${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
+46
View File
@@ -0,0 +1,46 @@
# This isn't perfect behavior, but it establishes a baseline and will provide
# a way to detect behavior changes
echo a1
a[0]= a[1]=; recho "${a[@]:-y}"
unset a
echo a2
a[1]=; recho "${a[@]:-y}"
a[1]=; recho "${a[*]:-z}"
unset a
echo a3
a[0]= a[1]=x; recho "${a[@]:-y}"
unset a
echo a4
a[0]= a[1]=x; recho ${a[@]:+y}
unset a
echo p1
set '' ''
recho "${@:-y}"
shift $#
echo p2
set '' x
recho "${@:-y}"
shift $#
echo p3
set '' x
recho ${@:+y}
# problems with * and null expansions dating back to bash's earliest days
A=(''); set -- ''
echo "<${A[*]:-X}>" "<${*:-X}>" "<${A:-X}>" "<${A[0]:-X}>"
IFS=
A=('' ''); set -- '' ''
B=''
echo "<${A[*]:-X}>" "<${*:-X}>" "<${B:-X}>" "<${B[*]:-X}>"
+28
View File
@@ -0,0 +1,28 @@
# this captures how bash and ksh93 expand indexed array subscripts in
# various contexts. if changes are ever made, or an option added to do
# this differently, the diffs will show up here
typeset -a array
index='$( echo >&2 foo )' # Literal shell code should never be evaluated unless an 'eval' is involved.
echo ${array[ $index ]} # [] expands $index, results in a literal that [] does not re-evaluate.
echo $(( $index )) # (( )) expands $index, results in a literal that (( )) does not re-evaluate.
echo $(( array[ $index ] )) # (( )) expands $index, results in a literal that [] DOES re-evaluate.
(( array[ $index ] ))
typeset -a a
: $(( a[$index]=5 ))
#shopt -s assoc_expand_once
echo $((1+a[$index]))
echo $((1+a[\$index]))
echo "1+${a[$index]}"
# intermediate problems discovered while bash-5.0 was in testing
a=0
echo $(( a[a[0]] ))
echo ${a[a[a[0]]]}
echo $(( a[a[a[0]]] ))
+47
View File
@@ -0,0 +1,47 @@
set -- "abc" "def ghi" "jkl"
A=("$@")
IFS=':'
echo 'IFS=: ${var-$*}'
unset var; printf '%s\n' ${var-$*}
printf '%s\n' ${var-${A[*]}}
echo "----"
echo 'IFS=: ${var=$*}'
unset var; printf '%s\n' ${var=$*}
printf 'var=%s\n' "$var"
unset var; printf '%s\n' ${var=${A[*]}}
printf 'var=%s\n' "$var"
echo "----"
echo 'IFS=: ${var+$*}'
printf '%s\n' ${var+$*}
printf '%s\n' ${var+${A[*]}}
echo "----"
echo 'IFS= ${var-$*}'
IFS=''
unset var; printf '%s\n' ${var-$*}
unset var; printf '%s\n' ${var-${A[*]}}
echo "----"
echo 'IFS= ${var=$*}'
unset var
printf '%s\n' ${var=$*}
printf 'var=%s\n' "$var"
unset var
printf '%s\n' ${var=${A[*]}}
printf 'var=%s\n' "$var"
echo "----"
echo 'IFS= ${var+$*}'
printf '%s\n' ${var+$*}
printf '%s\n' ${var+${A[*]}}
+70
View File
@@ -0,0 +1,70 @@
# tests with blank subscripts, indexed and associative
echo 1. indexed:
a[0]=0 a[1]=1
v=" "
echo reference:
echo 1. ${a[ ]}
echo 2. ${a[' ']}
echo 3. "${a[ ]}"
echo 4. ${a[$v]}
echo 5. ${a["$v"]}
echo 6. "${a[$v]}"
echo assignment:
echo -n 1. ; a[ ]=10 ; typeset -p a ; a[0]=0
echo -n 2. ; a[" "]=11 ; typeset -p a ; a[0]=0
echo -n 3. ; a[$v]=12 ; typeset -p a ; a[0]=0
echo -n 4. ; a["$v"]=13 ; typeset -p a ; a[0]=0
echo arithmetic:
echo -n 1. ; (( a[ ]=10 )); typeset -p a ; a[0]=0
echo -n 2. ; (( a[" "]=11 )); typeset -p a ; a[0]=0
echo -n 3. ; (( a[$v]=12 )); typeset -p a ; a[0]=0
echo -n 4. ; (( a["$v"]=13 )); typeset -p a ; a[0]=0
echo -n 5. ; let "a[ ]=10" ; typeset -p a ; a[0]=0
echo -n 6. ; let "a[\" \"]=11" ; typeset -p a ; a[0]=0
echo -n 7. ; let "a[$v]=12" ; typeset -p a ; a[0]=0
echo -n 8. ; let "a[\"$v\"]=13" ; typeset -p a ; a[0]=0
unset -v a v
echo 2. associative:
shopt -s assoc_expand_once
typeset -A a
a[0]=0 a[1]=1
v=" "
echo reference:
echo 1. ${a[ ]}
echo 2. ${a[' ']}
echo 3. "${a[ ]}"
echo 4. ${a[$v]}
echo 5. ${a["$v"]}
echo 6. "${a[$v]}"
echo assignment:
echo -n 1. ; a[ ]=10 ; typeset -p a ; a[0]=0
echo -n 2. ; a[" "]=11 ; typeset -p a ; a[0]=0
echo -n 3. ; a[$v]=12 ; typeset -p a ; a[0]=0
echo -n 4. ; a["$v"]=13 ; typeset -p a ; a[0]=0
echo arithmetic:
echo -n 1. ; (( a[ ]=10 )); typeset -p a ; a[0]=0
echo -n 2. ; (( a[" "]=11 )); typeset -p a ; a[0]=0
echo -n 3. ; (( a[$v]=12 )); typeset -p a ; a[0]=0
echo -n 4. ; (( a["$v"]=13 )); typeset -p a ; a[0]=0
echo -n 5. ; let "a[ ]=10" ; typeset -p a ; a[0]=0
echo -n 6. ; let "a[\" \"]=11" ; typeset -p a ; a[0]=0
echo -n 7. ; let "a[$v]=12" ; typeset -p a ; a[0]=0
echo -n 8. ; let "a[\"$v\"]=13" ; typeset -p a ; a[0]=0
+118
View File
@@ -0,0 +1,118 @@
# these should produce the same results
a=(aa bb)
set -- aa bb
IFS=+
recho ${a[@]}
recho ${a[@]:0}
recho $@
recho ${@:1}
A=${a[*]} B=${a[*]:0}
recho $* ${*:1}
recho ${a[*]} ${a[*]:0}
recho "$A" "$B"
recho $A $B
unset A B
recho ${@/a/x}
recho ${a[@]/a/x}
recho "${@/a/x}"
recho "${a[@]/a/x}"
recho ${*/a/x}
recho ${a[*]/a/x}
recho "${*/a/x}"
recho "${a[*]/a/x}"
A=${*/a/x}
B=${a[*]/a/x}
recho "$A" "$B"
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]/a/x}
recho "${A[@]/a/x}"
recho ${A[*]/a/x}
recho "${A[*]/a/x}"
unset A
IFS=
recho ${@/a/x}
recho ${a[@]/a/x}
recho "${@/a/x}"
recho "${a[@]/a/x}"
recho ${*/a/x}
recho ${a[*]/a/x}
recho "${*/a/x}"
recho "${a[*]/a/x}"
A=${*/a/x}
B=${a[*]/a/x}
recho "$A" "$B"
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]/a/x}
recho "${A[@]/a/x}"
recho ${A[*]/a/x}
recho "${A[*]/a/x}"
unset A
IFS=+
recho ${a[@]}
recho ${a[@],,}
recho "${a[@]}"
recho "${a[@],,}"
A=${a[*]} B=${a[*],,}
recho $* ${*,,}
recho ${a[*]} ${a[*],,}
recho "${a[*]}" "${a[*],,}"
recho "$A" "$B"
recho $A $B
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@],,}
recho "${A[@],,}"
recho ${A[*],,}
recho "${A[*],,}"
unset A
recho ${a[@]#?}
recho ${@#?}
A=${a[*]#?} B=${a[*]#?}
recho ${*#?} ${a[*]#?}
recho "$A" "$B"
recho $A $B
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]#?}
recho "${A[@]#?}"
recho ${A[*]#?}
recho "${A[*]#?}"
+59
View File
@@ -0,0 +1,59 @@
# tests for `problem' keys when using associative arrays and assoc_expand_once
# deal with problems for now; this is a placeholder for if and when I fix them
typeset -A a
shopt -s assoc_expand_once
k='['
echo $(( a[$k]=7 ))
k=']'
echo $(( a[$k]=7 ))
unset a
declare -A A
for k in $'\t' ' '; do
(( A[$k]=2 ))
done
declare -p A
for k in ']' '*' '@'; do
(( A[$k]=2 ))
done
declare -p A
unset A
declare -A A
for k in $'\t' ' ' ']' '*' '@'; do
read "A[$k]" <<< X
done
declare -p A
unset A
declare -A A
for k in $'\t' ' ' ']' '*' '@'; do
printf -v "A[$k]" "%s" X
done
declare -p A
unset A
declare -A A
for k in ']' '*' '@'; do
declare A[$k]=X
done
declare -p A
unset A
declare -A A
for k in ']' '*' '@'; do
declare "A[$k]=X"
done
declare -p A
+1 -1
View File
@@ -4,7 +4,7 @@
mkdir $TMPDIR/bash-test-$$
cd $TMPDIR/bash-test-$$
trap "cd / ; rm -rf $TMPDIR/bash-test-$$" 0 1 2 3 6 15
trap "cd $OLDPWD ; rm -rf $TMPDIR/bash-test-$$" 0 1 2 3 6 15
touch '[3]=abcde'
+114 -80
View File
@@ -3,43 +3,43 @@ 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=([foo]="one" [bar]="two" )
declare -A fluff=([foo]="one" [bar]="two" )
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=([two]="b" [three]="c" [one]="a" [zero]="0" )
declare -A chaff=([one]="10" ["hello world"]="flip" [zero]="5" )
declare -Ai chaff=([zero]="5" [one]="10" )
declare -Ar waste=([lineno]="28" [source]="./assoc.tests" [version]="4.0-devel" [pid]="42134" )
declare -A wheat=([two]="b" [three]="c" [zero]="0" [one]="a" )
declare -A chaff=(["hello world"]="flip" [zero]="5" [one]="10" )
./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" )
declare -A chaff=(["hello world"]="flip" [one]="a" )
flip
argv[1] = <a>
argv[1] = <multiple>
argv[2] = <words>
argv[3] = <flip>
argv[4] = <a>
argv[1] = <multiple words>
argv[2] = <flip>
argv[3] = <multiple>
argv[4] = <words>
argv[1] = <a>
argv[2] = <flip>
argv[3] = <multiple words>
argv[1] = <a>
argv[2] = <flip>
argv[3] = <multiple>
argv[4] = <words>
argv[1] = <a flip multiple words>
argv[3] = <a>
argv[1] = <multiple>
argv[2] = <words>
argv[3] = <flip>
argv[4] = <a>
argv[1] = <multiple words flip a>
./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" )
declare -A wheat=(["foo bar"]="qux qix" [six]="6" )
argv[1] = <qux>
argv[2] = <qix>
argv[1] = <qux qix>
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
declare -A wheat=(["foo bar"]="qux qix" [six]="6" )
argv[1] = <2>
argv[1] = <7>
argv[1] = <qux>
@@ -48,16 +48,16 @@ argv[3] = <blat>
argv[1] = <qux qix blat>
argv[1] = <16>
argv[1] = <16>
argv[1] = <6>
argv[2] = <flix>
argv[1] = <six>
argv[2] = <foo>
argv[3] = <bar>
argv[1] = <six>
argv[2] = <foo bar>
argv[1] = <flix>
argv[2] = <6>
argv[1] = <foo>
argv[2] = <bar>
argv[3] = <six>
argv[1] = <foo bar>
argv[2] = <six>
8
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
/sbin /usr/bin /bin /usr/ucb /usr/local/bin . /usr/sbin /bin
sbin bin bin ucb bin . sbin bin
bin
/ / / / / / /
/
@@ -66,83 +66,83 @@ argv[1] = </>
argv[1] = <sbin>
argv[1] = </>
8
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
/sbin /usr/bin /bin /usr/ucb /usr/local/bin . /usr/sbin /bin
sbin bin bin ucb bin . sbin bin
/ / / / / / /
8
4 -- /bin
. ^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
^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin . ^usr^sbin ^bin
^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin . ^usr^sbin ^bin
\sbin \usr/bin \bin \usr/ucb \usr/local/bin . \usr/sbin \bin
\sbin \usr\bin \bin \usr\ucb \usr\local\bin . \usr\sbin \bin
\sbin \usr\bin \bin \usr\ucb \usr\local\bin . \usr\sbin \bin
([a]=1)
qux foo
/usr/local/bin/qux /usr/sbin/foo
foo qux
/usr/sbin/foo /usr/local/bin/qux
hits command
0 /sbin/blat
0 /usr/local/bin/qux
0 /bin/sh
0 /usr/sbin/foo
blat qux sh foo
/sbin/blat /usr/local/bin/qux /bin/sh /usr/sbin/foo
0 /bin/sh
0 /usr/local/bin/qux
blat foo sh qux
/sbin/blat /usr/sbin/foo /bin/sh /usr/local/bin/qux
qux foo
argv[1] = </usr/local/bin/qux>
argv[2] = <-l>
argv[3] = </usr/sbin/foo>
foo qux
argv[1] = </usr/sbin/foo>
argv[2] = </usr/local/bin/qux>
argv[3] = <-l>
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'
blat qux sh foo
blat foo sh qux
argv[1] = <cd /blat ; echo $PWD>
argv[2] = </usr/local/bin/qux -l>
argv[2] = </usr/sbin/foo>
argv[3] = </bin/bash --login -o posix>
argv[4] = </usr/sbin/foo>
argv[4] = </usr/local/bin/qux -l>
outside: outside
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A afoo=([six]="six" ["foo bar"]="foo quux" )
declare -A afoo=(["foo bar"]="foo quux" [six]="six" )
argv[1] = <inside:>
argv[2] = <six>
argv[3] = <foo quux>
argv[2] = <foo quux>
argv[3] = <six>
outside 2: outside
argv[1] = <fooq//barq/>
argv[1] = <fooq>
argv[2] = <>
argv[3] = <barq>
argv[4] = <>
argv[1] = <foo!//bar!/>
argv[1] = <foo!>
argv[2] = <>
argv[3] = <bar!>
argv[4] = <>
argv[1] = <ooq//arq/>
argv[1] = <ooq>
argv[2] = <>
argv[3] = <arq>
argv[4] = <>
argv[1] = <Fooq//Barq/>
argv[1] = <Fooq>
argv[2] = <>
argv[3] = <Barq>
argv[4] = <>
argv[1] = <FOOQ//BARQ/>
argv[1] = <FOOQ>
argv[2] = <>
argv[3] = <BARQ>
argv[4] = <>
argv[1] = </barq//fooq>
argv[1] = <>
argv[2] = <barq>
argv[3] = <>
argv[4] = <fooq>
argv[1] = </bar!//foo!>
argv[1] = <>
argv[2] = <bar!>
argv[3] = <>
argv[4] = <foo!>
argv[1] = </arq//ooq>
argv[1] = <>
argv[2] = <arq>
argv[3] = <>
argv[4] = <ooq>
argv[1] = </Barq//Fooq>
argv[1] = <>
argv[2] = <Barq>
argv[3] = <>
argv[4] = <Fooq>
argv[1] = </BARQ//FOOQ>
argv[1] = <>
argv[2] = <BARQ>
argv[3] = <>
argv[4] = <FOOQ>
abc
def
def
./assoc5.sub: line 13: declare: `myarray[foo[bar]=bleh': not a valid identifier
bleh abc def
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["]"]="def" )
bleh def abc
myarray=([foo]="bleh" ["]"]="def" ["a]=test1;#a"]="123" ["a]a"]="abc" )
123
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["a]=test2;#a"]="def" ["]"]="def" )
myarray=([foo]="bleh" ["]"]="def" ["a]=test2;#a"]="def" ["a]=test1;#a"]="123" ["a]a"]="abc" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
@@ -195,3 +195,37 @@ declare -A assoc=([0]="assoc" )
assoc
declare -A assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -Ar assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -A b=([")"]="" ["\""]="" ["]"]="" ["\\"]="" ["\`"]="" )
declare -A b=(["]"]="" ["\`"]="" )
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
./assoc9.sub: line 23: unset: `dict[']': not a valid identifier
./assoc9.sub: line 23: unset: `dict["]': not a valid identifier
./assoc9.sub: line 23: unset: `dict[\]': not a valid identifier
./assoc9.sub: line 23: unset: `dict[`]': not a valid identifier
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
declare -A dict=()
4
4
a[$b]= 5
declare -A a=(["80's"]="Depeche Mode" )
./assoc9.sub: line 71: read: `a[80's]': not a valid identifier
declare -A a
declare -A a=(["80's"]="Depeche Mode" )
./assoc9.sub: line 83: printf: `a[80's]': not a valid identifier
declare -A a
declare -A a=(["80's"]="Depeche Mode" )
6
1
1+5
declare -A a=(["\$(date >&2)"]="5" )
declare -A myarray=([foo]="bleh" ["foo[bar"]="bleh" )
./assoc10.sub: line 1: declare: a: cannot convert indexed to associative array
f: declare -a a
./assoc10.sub: line 4: declare: a: cannot convert associative to indexed array
f: declare -A a
f: declare -a a
main: declare -- a="7"
f: declare -A a
main: declare -- a="42"
+13 -1
View File
@@ -107,7 +107,7 @@ unset flix wheat
# TEST - index expansion: no word splitting or globbing
typeset -A wheat
cd /tmp
cd ${TMPDIR:=/tmp}
touch '[sfiri]'
wheat=([s*]=6 [foo bar]=flix )
@@ -174,6 +174,13 @@ T='([a]=1)'
echo "${T[@]}"
unset T
# peculiar ksh93 semantics for unsubscripted assoc variable reference
declare -A T
T[0]='zero'
if [ "$T" != "${T[0]}" ]; then
echo 'assoc.tests: $T and ${T[0]} mismatch'
fi
${THIS_SH} ./assoc1.sub
${THIS_SH} ./assoc2.sub
@@ -207,3 +214,8 @@ readonly -A assoc
declare -p assoc
${THIS_SH} ./assoc8.sub
# new shopt option to prevent multiple expansion of assoc array subscripts
${THIS_SH} ./assoc9.sub
${THIS_SH} ./assoc10.sub
+17
View File
@@ -0,0 +1,17 @@
f() { declare -a a; declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
f
f() { declare -A a; declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
f
echo
f() { declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
a=7
f
echo -n 'main: '; declare -p a
f() { declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
a=42
f
echo -n 'main: '; declare -p a
+110
View File
@@ -0,0 +1,110 @@
typeset -A a=( [\\]= [\"]= [\)]= ) b
for x in "${!a[@]}"; do b[$x]=; done
b+=([\`]= [\]]=)
typeset -p b
for x in "${!a[@]}"; do
unset -v 'b[$x]'
done
typeset -p b
unset -v a b
loaddict()
{
dict['"']=1
dict['`']=2
dict["'"]=3
dict['\']=4
declare -p dict
}
del()
{
unset -v dict["$1"];
}
declare -A dict
loaddict
for k in "${!dict[@]}"; do del "$k"; done
declare -p dict
unset 'dict[@]'
shopt -s assoc_expand_once
declare -A dict
loaddict
for k in "${!dict[@]}"; do del "$k"; done
declare -p dict
unset a b dict
typeset -A a
b="80's"
((++a[$b]))
((++a["$b"]))
[[ $((++a[$b])) ]]
[[ $((++a["$b"])) ]]
echo ${a["$b"]}
echo ${a[$b]}
let "++a[$b]"
echo 'a[$b]=' "${a[$b]}"
unset a b
declare -A a
b="80's"
: ${a[$b]:='Depeche Mode'}
declare -p a
unset a b
shopt -u assoc_expand_once
typeset -A a
b="80's"
read a[$b] <<<"Depeche Mode"
typeset -p a
shopt -s assoc_expand_once
read a[$b] <<<"Depeche Mode"
typeset -p a
unset a
shopt -u assoc_expand_once
typeset -A a
printf -v a[$b] "%s" "Depeche Mode"
typeset -p a
shopt -s assoc_expand_once
printf -v a[$b] "%s" "Depeche Mode"
typeset -p a
unset a
declare -A a
x='$(date >&2)'
a[$x]=5
shopt -s assoc_expand_once
echo $((1+a[$x]))
echo $((1+a[\$x]))
echo "1+${a[$x]}"
declare -p a
shopt -s assoc_expand_once
declare -A myarray
declare myarray["foo[bar"]=bleh
myarray["foo"]=bleh
declare -p myarray
+35
View File
@@ -25,3 +25,38 @@ ok 8
ok 9
mysterious 1
mysterious 2
argv[1] = <\a\b\c\^A\d\e\f>
argv[1] = <\a\b\c\^A\d\e\f>
argv[1] = <abc^Adef>
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
--- testing: soh
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
--- testing: stx
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
--- testing: del
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
ok1ok2ok3ok4ok5
+3
View File
@@ -51,3 +51,6 @@ case " " in ( [" "] ) echo ok;; ( * ) echo no;; esac
# tests of quote removal and pattern matching
${THIS_SH} ./case1.sub
${THIS_SH} ./case2.sub
${THIS_SH} ./case3.sub
${THIS_SH} ./case4.sub
+52
View File
@@ -0,0 +1,52 @@
x=$'\\a\\b\\c\\\001\\d\\e\\f'
y='\a\b\c\\d\e\f'
z=$'abc\001def'
recho "$x"
recho "$y"
recho "$z"
case $'abc\001def' in
$x) echo ok 1 ;;
*) echo oops 1;;
esac
case $z in
$x) echo ok 2 ;;
*) echo oops 2;;
esac
case $'abc\001def' in
$y) echo ok 3 ;;
*) echo oops 3;;
esac
case $z in
$y) echo ok 4 ;;
*) echo oops 4;;
esac
# no backslash before \001
x=$'\\a\\b\\c\001\\d\\e\\f'
y='\a\b\c\d\e\f'
case $'abc\001def' in
$x) echo ok 5 ;;
*) echo oops 5;;
esac
case $z in
$x) echo ok 6 ;;
*) echo oops 6;;
esac
case $'abc\001def' in
$y) echo ok 7 ;;
*) echo oops 7;;
esac
case $z in
$y) echo ok 8 ;;
*) echo oops 8;;
esac
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
testmatch() {
case $1 in
( $2 ) printf ok1 ;;
( * ) printf fail1 ;;
esac
case $1,$2 in
( $2,"$2" ) printf ok2 ;;
( * ) printf fail2 ;;
esac
case $1, in
( $2, ) printf ok3 ;;
( * ) printf fail3 ;;
esac
case ,$2 in
( ,"$2" ) printf ok4 ;;
( * ) printf fail4 ;;
esac
case "$1,$2" in
( $2,"$2" ) printf ok5 ;;
( * ) printf fail5 ;;
esac
echo
}
for c in $'\1' $'\2' $'\177'; do
echo -n "--- testing: "
echo "$c" | od -t a | awk 'NR==1 { print $2 } '
testmatch "${c}" "\\${c}"
testmatch "${c}x" "\\${c}\\x" # bash-git fails case 2 and 5 for $'\1'
testmatch "${c}x" "${c}\\x"
testmatch "${c}x" "${c}x"
testmatch "${c}x" "\\${c}x"
testmatch "x${c}" "\\x\\${c}"
testmatch "x${c}" "x\\${c}"
done
match() { case $1 in ( $2 ) ;; ( * ) return 1 ;; esac; }
match $'? *x\1y\177z' $'??\\*\\x\\\1\\y\\\177\\z' || echo bad 6
+25
View File
@@ -0,0 +1,25 @@
shopt -s -o posix
two="t w o"
ten="t e
n"
set 1 "$two" 3 4 5 6 7 8 9 "$ten"
unset IFS
expvar="$*"
case $* in
"$expvar") ;;
*) echo "failed 1" ;;
esac
case $* in
$expvar) ;;
*) echo "failed 2" ;;
esac
alias foo='oneword'
foo_word='foo'
case "$foo_word"
in
foo) ;;
*) echo failed 3;;
esac
+4 -4
View File
@@ -13,10 +13,10 @@ aCKNOWLEDGEMENT oENOPHILE
aCKNoWLeDGeMeNT oeNoPHiLe
aCKNOWLEDGEMENT oENOPHILE
acknowledgement oenophile
Acknowledgement Oenophile
ACKNOWLEDGEMENT OENOPHILE
Acknowledgement Oenophile
AcknOwlEdgEmEnt OEnOphIlE
Oenophile Acknowledgement
OENOPHILE ACKNOWLEDGEMENT
Oenophile Acknowledgement
OEnOphIlE AcknOwlEdgEmEnt
oENOPHILE aCKNOWLEDGEMENT
oenophile acknowledgement
oENOPHILE aCKNOWLEDGEMENT
+1
View File
@@ -1,3 +1,4 @@
: ${HOME:=/}
# works right
echo ab$(echo mnop)yz
+7
View File
@@ -28,6 +28,7 @@ ok 4
ok 5
ok 6
xyz
ok 7
\/tmp\/foo\/bar
/tmp/foo/bar
/tmp/foo/bar
@@ -48,3 +49,9 @@ b
c
1
2
d \
g
d \
g
d \
g
+13
View File
@@ -44,6 +44,19 @@ bar')
# long-standing parse error in all versions up through bash-4.3
echo ${foo:-$(echo a{b,c})} >/dev/null
# parsing problem based on recursively calling bison parser through bash-4.4
for (( INDEX=0; INDEX<$((10-$(echo length $V_NAME))); INDEX++ ))
do
:
done
# problem with four-character words followed by a metachar through bash-4.4
comsub_foo_1()
{
echo $(while true; do case $HOME in /*) echo abs ;; esac; done)
}
${THIS_SH} ./comsub1.sub
${THIS_SH} ./comsub2.sub
${THIS_SH} ./comsub3.sub
${THIS_SH} ./comsub4.sub
+6
View File
@@ -52,3 +52,9 @@ echo $( # we just took and pasted in some
# command substitution
echo xyz
)
# problem with parse_comsub through bash-4.4
case $(echo $$'x\nx') in
x*) echo bad 7;;
*) echo ok 7;;
esac
+3 -3
View File
@@ -3,6 +3,6 @@ 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 "\\\\\\\\"`/}
printf "%s\n" ${qpath//\\/}
printf "%s\n" ${qpath//"`printf '%s' \\`"/}
printf "%s\n" ${qpath//`printf '%s' "\\\\\\\\"`/}
+27
View File
@@ -0,0 +1,27 @@
x=$(cat <<'EOT'
d \
g
EOT
)
echo "$x"
unset x
x=$( cat <<\EOT\
4
d \
g
EOT4
)
echo "$x"
unset x
x=$( cat <<\EOT
d \
g
EOT
)
echo "$x"
+2
View File
@@ -28,3 +28,5 @@
[[ ']' =~ [']'] ]] && echo ok 11
[[ a =~ ['a]'] ]] || echo ok 12
[[ "\\" =~ [^]"."] ]] || echo unexpected
+3
View File
@@ -180,6 +180,9 @@ 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
match() { [[ $1 == $2 ]]; }
match $'? *x\1y\177z' $'??\\*\\x\\\1\\y\\\177\\z' || echo bad 44
foo=""
[[ bar == *"${foo,,}"* ]] && echo ok 1
[[ bar == *${foo,,}* ]] && echo ok 2
+2 -2
View File
@@ -30,8 +30,8 @@ read LINE <&${REFLECT[0]}
echo $LINE
{ 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 || {
wait $REFLECT_PID >$TMPOUT 2>&1 || { status=$? ; echo "coproc.tests: REFLECT: status $status" ; }
[[ $status < 128 || $status == 143 ]] || {
echo "coproc.tests: wait for REFLECT failed" >&2
}
rm -f $TMPOUT
+31
View File
@@ -6,6 +6,23 @@ recho "$*"
recho $@
recho $*
foo=$*
foo=$@
foo="$*"
foo="$@"
unset -v bar
foo=${bar:-$*}
foo=${bar:-$@}
foo=${bar:-"$*"}
foo=${bar:-"$@"}
foo=${!*}
foo=${!@}
set a b
recho "$*"
@@ -271,4 +288,18 @@ ${THIS_SH} ./dollar-star6.sub
# problem through bash-4.2
${THIS_SH} ./dollar-star7.sub
# tests for expansions of $* (unquoted) when IFS is null and word splitting is
# not going to be performed.
# problem through bash-4.4 in some parameter expansion contexts
${THIS_SH} ./dollar-star8.sub
# tests for expansions of "$@" when there are no positional parameter or when
# $1 == '' and the expansion is preceded by something that results in a quoted
# null string
${THIS_SH} ./dollar-at7.sub
# tests for expansions of $* when in an assignment context (no splitting) and
# IFS is null
${THIS_SH} ./dollar-star9.sub
exit 0
+2
View File
@@ -33,10 +33,12 @@ unset a
unset IFS
set a b "c d"
printf '<%s>' $* ; echo
printf '<%s>' ${q-$*} ; echo
IFS=
set a b "c d"
printf '<%s>' $* ; echo
printf '<%s>' ${q-$*} ; echo
IFS=:
set a b
+46
View File
@@ -0,0 +1,46 @@
set -- ''
recho 1 ''"$@"
recho 2 """$@"
recho 3 "$@""$@"
recho 4 "$x""$@"
set --
echo -----
recho 1 ''"$@"
recho 2 """$@"
recho 3 "$@""$@"
recho 4 "$x""$@"
set -- X
echo ------
recho 1 ''"${@/*}"
recho 2 """${@/*}"
recho 3 "$x""${@/*}"
recho 4 ''"${@#X}"
recho 5 """${@#X}"
recho 6 "$x""${@#X}"
set --
echo -----
recho 1 ''"${@/*}"
recho 2 """${@/*}"
recho 3 "$x""${@/*}"
recho 4 ''"${@#X}"
recho 5 """${@#X}"
recho 6 "$x""${@#X}"
echo -----
recho 1 "$novar${*}$(echo)"
recho 2 ''"$novar${@}$(echo)"
+21
View File
@@ -0,0 +1,21 @@
IFS=
set "abc" "def ghi" "jkl"
set ${1+$*}
printf '<%s>\n' "$#" "$@"
set "abc" "def ghi" "jkl"
set $*
printf '<%s>\n' "$#" "$@"
printf '<%s>\n' $* ;
printf '<%s>\n' ${q:-$*}
printf '<%s>\n' "${q:-$*}"
IFS=:
printf '<%s>\n' $* ;
printf '<%s>\n' ${q:-$*}
printf '<%s>\n' "${q:-$*}"
unset -v IFS
printf '<%s>\n' $* $@
+46
View File
@@ -0,0 +1,46 @@
set -- 1 2
IFS=
a=$* b=${*}
c=${*/} d=${*#} e=${*%} f=${*:1}
printf '<%s>' "$a" "$b" "$c" "$d" "$e" "$f"; echo
unset a b c d e f
: ${a=$*} ${b=${*}} ${c=${*/}}
: ${d=${*#}} ${e=${*%}} ${f=${*:1}}
printf '<%s>' "$a" "$b" "$c" "$d" "$e" "$f" ; echo
unset f g
f=${*,,} g=${*@Q}
printf '<%s>' "$f" "$g" ; echo
unset -v a b c d e f g
unset var
# resetting IFS here
IFS=$' \t\n'
printf '%s\n' "${*:1}"
var=${*:1}; printf '%s\n' "$var"
var="${*:1}"; printf '%s\n' "$var"
unset var
recho ${var-${*}}
recho ${var-${*:1}}
recho "${var-${*:1}}"
recho ${var-"${*:1}"}
unset var
recho ${var=${*}}
printf 'var=%s\n' "$var"
unset var
recho ${var=${*:1}}
printf 'var=%s\n' "$var"
a=${*:1}
recho "$a"
: ${b=${*:1}}
recho "$b"
+99
View File
@@ -177,6 +177,8 @@ ab
a b
a b
<a><b><c><d>
<a><b><c><d>
<a><b><c d>
<a><b><c d>
<a><b>
<a:b>
@@ -478,3 +480,100 @@ argv[2] = <b>
argv[3] = <c>
argv[4] = <d>
argv[1] = <a b c d>
<3>
<abc>
<def ghi>
<jkl>
<3>
<abc>
<def ghi>
<jkl>
<abc>
<def ghi>
<jkl>
<abc>
<def ghi>
<jkl>
<abcdef ghijkl>
<abc>
<def ghi>
<jkl>
<abc>
<def ghi>
<jkl>
<abc:def ghi:jkl>
<abc>
<def>
<ghi>
<jkl>
<abc>
<def>
<ghi>
<jkl>
argv[1] = <1>
argv[2] = <>
argv[1] = <2>
argv[2] = <>
argv[1] = <3>
argv[2] = <>
argv[1] = <4>
argv[2] = <>
-----
argv[1] = <1>
argv[2] = <>
argv[1] = <2>
argv[2] = <>
argv[1] = <3>
argv[1] = <4>
argv[2] = <>
------
argv[1] = <1>
argv[2] = <>
argv[1] = <2>
argv[2] = <>
argv[1] = <3>
argv[2] = <>
argv[1] = <4>
argv[2] = <>
argv[1] = <5>
argv[2] = <>
argv[1] = <6>
argv[2] = <>
-----
argv[1] = <1>
argv[2] = <>
argv[1] = <2>
argv[2] = <>
argv[1] = <3>
argv[2] = <>
argv[1] = <4>
argv[2] = <>
argv[1] = <5>
argv[2] = <>
argv[1] = <6>
argv[2] = <>
-----
argv[1] = <1>
argv[2] = <>
argv[1] = <2>
argv[2] = <>
<12><12><12><12><12><12>
<12><12><12><12><12><12>
<12><'1''2'>
1 2
1 2
1 2
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1 2>
argv[1] = <1 2>
argv[1] = <1>
argv[2] = <2>
var=1 2
argv[1] = <1>
argv[2] = <2>
var=1 2
argv[1] = <1 2>
argv[1] = <1 2>
+3
View File
@@ -1,3 +1,4 @@
wdir=$PWD
cd /
echo expect '~1'
@@ -31,3 +32,5 @@ dirs -v -1
echo these lines should be the same
dirs -0
echo ~-0 ${DIRSTACK[NDIRS]}
cd "$wdir"
+7
View File
@@ -0,0 +1,7 @@
BASHPID ok
BASH_ARGV0 ok
BASH_ARGV0 ok
SECONDS ok
EPOCHSECONDS ok
EPOCHREALTIME ok
echo $BASH_COMMAND
+77
View File
@@ -0,0 +1,77 @@
# specvar -- test some of the dynamic variables
# BASHPID
pid=$$
bpid=$BASHPID
subpid=$( (echo $BASHPID) )
if [ "$bpid" -ne "$subpid" ]; then echo BASHPID ok; fi
# BASH_ARGV0
BASH_ARGV0=hello
case $0 in
hello) echo BASH_ARGV0 ok ;;
*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
esac
setarg0()
{
BASH_ARGV0="$1"
}
setarg0 arg0
case $0 in
arg0) echo BASH_ARGV0 ok ;;
*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
esac
# SECONDS
before=$SECONDS
sleep 2
after=$SECONDS
if (( $after > $before )); then echo SECONDS ok; fi
unset before after
# EPOCHSECONDS
# not exact, but should work
now1=$(perl -e 'print time')
now2=$EPOCHSECONDS
case $now1 in
$now2) echo EPOCHSECONDS ok ;;
*) echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;;
esac
unset now1 now2
LC_ALL=C # force decimal point to `.'
now1=$EPOCHREALTIME
now2=$EPOCHREALTIME
sec1=${now1%%.*}
sec2=${now2%%.*}
msec1=${now1##*.}
msec2=${now2##*.}
# cut off leading zeros
shopt -s extglob
msec1=${msec1##*(0)}
msec2=${msec2##*(0)}
dsec=$(( $sec2 - $sec1 ))
dmsec=$(( $msec2 - $msec1 ))
if (( $dmsec < 0 )); then
dmsec=$(( dmsec + 1000000 ))
dsec=$(( desc - 1 ))
fi
# not a real test, but ok for a start
if (( $dmsec < 1000000 )); then echo EPOCHREALTIME ok; fi
${THIS_SH} -c 'echo $BASH_COMMAND'
# FUNCNAME tested in func.tests
# RANDOM tested in varenv.sh
# LINENO tested in dbg-support
+70 -8
View File
@@ -120,17 +120,79 @@ after readonly assignment
./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 8: array[7]: unbound variable
./errors5.sub: line 11: 7: unbound variable
./errors5.sub: line 12: 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
4
array after 1: 0
array after 2: 0
./errors6.sub: uvar: parameter not set
./errors6.sub: uvar: parameter null or not set
./errors6.sub: uvar: parameter null or not set
./errors6.sub: line 25: ${-3:-${-3}}: bad substitution
./errors6.sub: line 26: ${-3}: bad substitution
./errors6.sub: line 27: -3: invalid variable name
after indir: 1
./errors6.sub: line 18: ${-3}: bad substitution
./errors6.sub: line 19: -3: bad substitution
./errors6.sub: line 30: -3: invalid variable name
unset
./errors6.sub: line 37: var: invalid indirect expansion
./errors6.sub: line 38: var: invalid indirect expansion
./errors6.sub: line 41: invalid-ident: invalid variable name
./errors6.sub: line 42: invalid-ident: invalid variable name
./errors6.sub: line 43: invalid-ident: invalid variable name
4
array after 1: 0
array after 2: 0
./errors6.sub: uvar: parameter not set
./errors6.sub: uvar: parameter null or not set
./errors6.sub: uvar: parameter null or not set
./errors6.sub: line 25: ${-3:-${-3}}: bad substitution
./errors6.sub: line 26: ${-3}: bad substitution
./errors6.sub: line 27: -3: invalid variable name
after indir: 1
./errors.tests: line 278: `!!': not a valid identifier
./errors6.sub: line 30: -3: invalid variable name
unset
./errors6.sub: line 37: var: invalid indirect expansion
./errors6.sub: line 38: var: invalid indirect expansion
./errors6.sub: line 41: invalid-ident: invalid variable name
./errors6.sub: line 42: invalid-ident: invalid variable name
./errors6.sub: line 43: invalid-ident: invalid variable name
./errors7.sub: line 8: x: readonly variable
./errors7.sub: line 8: notthere: command not found
after no such command: 127
./errors7.sub: line 10: x: readonly variable
echo builtin
after non-special builtin: 0
./errors7.sub: line 12: x: readonly variable
after special builtin: 0
./errors7.sub: line 14: x: readonly variable
./errors7.sub: line 8: x: readonly variable
./errors7.sub: line 8: notthere: command not found
after no such command: 127
./errors7.sub: line 10: x: readonly variable
echo builtin
after non-special builtin: 0
./errors7.sub: line 12: x: readonly variable
./errors7.sub: line 14: x: readonly variable
./errors8.sub: eval: line 7: syntax error: unexpected end of file
ok 1
./errors8.sub: line 8: v: readonly variable
ok 2
./errors8.sub: line 9: v: readonly variable
ok 3
./errors8.sub: line 11: shift: 12: shift count out of range
ok 4
./errors8.sub: line 13: return: can only `return' from a function or sourced script
ok 5
./errors8.sub: line 14: set: notanoption: invalid option name
ok 6
./errors.tests: line 283: `!!': not a valid identifier
+5
View File
@@ -270,6 +270,11 @@ ${THIS_SH} ./errors5.sub
${THIS_SH} ./errors6.sub
THIS_SH="${THIS_SH} -o posix" ${THIS_SH} ./errors6.sub
${THIS_SH} ./errors7.sub
${THIS_SH} -o posix ./errors7.sub
${THIS_SH} ./errors8.sub
# this must be last!
# in posix mode, a function name must be a valid identifier
# this can't go in posix2.tests, since it causes the shell to exit
+1
View File
@@ -5,6 +5,7 @@ set -u
( echo ${#array} )
( echo ${array} )
( echo ${array[7]} )
set -- 1 2 3
( echo ${#7} )
+23
View File
@@ -15,6 +15,29 @@ 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
${THIS_SH} -c 'echo ${uvar?}' ./errors6.sub
${THIS_SH} -c 'echo ${uvar:?}' ./errors6.sub
export uvar=
${THIS_SH} -c 'echo ${uvar?}' ./errors6.sub
${THIS_SH} -c 'echo ${uvar:?}' ./errors6.sub
unset uvar
echo "${-3:-${-3}}"
echo ${-3}
x=-3; echo ${!x}
echo after indir: $?
function ivar() { echo -n "${!1:-${1}}"; }
ivar -3
foo=bar
echo ${!foo}
echo ${!foo:-unset}
echo ${!var:-unset}
echo ${!var+unset}
foo=invalid-ident
echo ${!foo}
echo ${!foo:-unset}
echo ${!foo+unset}
+15
View File
@@ -0,0 +1,15 @@
: ${THIS_SH:=./bash}
readonly x=4
# in posix mode, these are all variable assignment errors, so strict conformance
# implies that we exit after any of them. ksh93 doesn't do that. we more-or-less
# emulate the ksh93 behavior
x=8 notthere
echo after no such command: $?
x=8 echo echo builtin
echo after non-special builtin: $?
( x=8 : nosuchdir
echo after special builtin: $? )
( x=8 $nocmd
echo after assignment error: $? )
+14
View File
@@ -0,0 +1,14 @@
# the start of a set of tests for command keeping special builtins from
# exiting the shell on failure
set -o posix
readonly v
command eval '( ' || echo ok 1
command export v=foo || echo ok 2
command readonly v=foo || echo ok 3
command shift 12 || echo ok 4
command return 16 || echo ok 5
command set -o notanoption || echo ok 6
+3 -3
View File
@@ -84,9 +84,9 @@ after
exit code: 1
exit code: 1
exit code: 1
exit code: 127
exit code: 127
exit code: 127
exit code: 1
exit code: 1
exit code: 1
a
b
c
+3 -1
View File
@@ -1,9 +1,11 @@
: ${TMPDIR:=/var/tmp}
TMPFILE=$TMPDIR/exitcode
trap 'rm -f $TMPFILE' 0
rm -f $TMPFILE
set -e
exit_handler() { echo "exit code: $?" ; touch $TMPFILE; }
# we normalize the exit code to accommodate false returning 255 on Solaris
exit_handler() { echo "exit code: $(( $? != 0 ))" ; touch $TMPFILE; }
false() { ! :; }
notfound() { nosuchcommand ; }
syntaxerror() { !:; }
+3
View File
@@ -18,3 +18,6 @@ chmod 755 testb/foo
PATH=$TMPDIR/testa:$TMPDIR/testb $THIS_SH -c foo
rm -rf testa testb
cd $OLDPWD
exit 0
+4 -4
View File
@@ -59,10 +59,10 @@ echo $?
echo $?
# kill two birds with one test -- test out the BASH_ENV code
echo echo this is bashenv > /tmp/bashenv
export BASH_ENV=/tmp/bashenv
echo echo this is bashenv > $TMPDIR/bashenv
export BASH_ENV=$TMPDIR/bashenv
${THIS_SH} ./exec3.sub
rm -f /tmp/bashenv
rm -f $TMPDIR/bashenv
unset BASH_ENV
# we're resetting the $PATH to empty, so this should be last
@@ -108,7 +108,7 @@ ${THIS_SH} ./exec6.sub
# checks for properly deciding what constitutes an executable file
${THIS_SH} ./exec7.sub
${THIS_SH} -i ./exec8.sub
${THIS_SH} -i ${PWD}/exec8.sub
${THIS_SH} ./exec9.sub
+74 -1
View File
@@ -216,6 +216,12 @@ argv[2] = <^C>
argv[3] = <^C>
argv[4] = <^C>
argv[1] = <^A>
argv[1] = <XY>
argv[2] = <YX>
argv[1] = <XY^AYX>
argv[1] = <XY>
argv[2] = <Y>
argv[1] = <XY^AY>
argv[1] = <x^Ay^?z>
argv[1] = <x^Ay^?z>
declare -- var="xyz"
@@ -291,7 +297,9 @@ var=abc:def ghi:jkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
abc
def ghi
jkl
abcdef ghijkl
abcdef ghijkl
abcdef ghijkl
@@ -332,3 +340,68 @@ jkl
[]
[foo]
[]
< A >< B >< A >< B >
< A >< B >< A >< B >
< A >< B >< a >< b >
< A >< B >< A >< B >
< A >< B ><' A '><' B '>
-----
< A >< B >< A >< B >
< A >< B >< A >< B >
< A >< B >< a >< b >
< A >< B >< A >< B >
< A >< B ><' A '><' B '>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1 2>
argv[1] = <a b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a b>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = <12>
argv[1] = <12>
argv[1] = <1>
argv[2] = <2>
argv[1] = <1>
argv[2] = <2>
argv[1] = < >
argv[1] = < >
argv[1] = < >
argv[1] = < >
argv[1] = < >
argv[1] = <12>
argv[1] = <12>
argv[1] = <12>
argv[1] = <12>
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
argv[1] = <file.o>
argv[1] = <posix>
argv[1] = </src/cmd>
argv[1] = <three>
argv[1] = </one/two/three>
abcdefg
abcdefg
abcdefg
abcdefg
cdefg
abcdefg
abcde
abcdefg
+3
View File
@@ -405,3 +405,6 @@ ${THIS_SH} ./exp6.sub
${THIS_SH} ./exp7.sub
${THIS_SH} ./exp8.sub
${THIS_SH} ./exp9.sub
${THIS_SH} ./exp10.sub
${THIS_SH} ./exp11.sub
${THIS_SH} ./exp12.sub
+26
View File
@@ -0,0 +1,26 @@
set -- ' A ' ' B '
IFS=
printf '<%s>' ${*} ${*##}
echo
printf '<%s>' ${*} ${*/}
echo
printf '<%s>' ${*} ${*,,}
echo
printf '<%s>' ${*} ${*:1:2}
echo
printf '<%s>' ${*} ${*@Q}
echo
echo -----
printf '<%s>' ${@} ${@##}
echo
printf '<%s>' ${@} ${@/}
echo
printf '<%s>' ${@} ${@,,}
echo
printf '<%s>' ${@} ${@:1:2}
echo
printf '<%s>' ${@} ${@@Q}
echo
+92
View File
@@ -0,0 +1,92 @@
set -- '1 2'
unset var
recho ${var-${*:1}}
unset var
recho ${var=$*}
unset var
recho ${var=${*:1}}
recho "$var"
# posix interp 221
unset var
recho ${var:-a\ b}
recho ${var:=a\ b}
recho "$var"
set -- 1 2
IFS=
unset a b c
recho $*
recho ${a-$*}
recho ${b-${*/}}
recho ${c=${*/}}
recho "$c"
recho ${b-${*,,}}
recho ${d-${*,,}}
unset -v a b c
IFS=$' \t\n'
set -- ' '
A=(' ')
IFS=
unset var
var=${*@E}
recho "$var"
unset var
var=${A[*]@E}
recho "$var"
unset var
var=${@@E}
recho "$var"
unset var
var=${A[@]@E}
recho "$var"
unset novar
recho ${novar-${A[*]@E}}
unset -v var novar
IFS=$' \t\n'
set -- 1 2
A=( 1 2 )
IFS=
a=$*
recho "$a"
b=${*@E}
recho "$b"
unset a b
a=${A[*]}
recho "$a"
b=${A[*]@E}
recho "$b"
set -- $'\t'
A=$1
IFS=$1
[[ ${A[@]} ]] && echo ok 1
[[ ${A[*]} ]] && echo ok 2
[[ ${A[0]} ]] && echo ok 3
IFS=$' \t\n'
[[ ${A[@]} ]] && echo ok 4
[[ ${A[*]} ]] && echo ok 5
[[ ${A[0]} ]] && echo ok 6
IFS=
[[ ${A[@]} ]] && echo ok 7
[[ ${A[*]} ]] && echo ok 8
[[ ${A[0]} ]] && echo ok 9
+38
View File
@@ -0,0 +1,38 @@
# force single-byte versions of these functions
export LANG=C
# remove shortest trailing match
x=file.c
recho ${x%.c}.o
# remove longest trailing match
x=posix/src/std
recho ${x%%/*}
# remove shortest leading pattern
x=$HOME/src/cmd
recho ${x#$HOME}
# remove longest leading pattern
x=/one/two/three
recho ${x##*/}
# and no match thrown in for good measure
recho ${x#nomatch}
foo=abcdefg
# fail
echo ${foo%ab}
echo ${foo%def}
echo ${foo#fg}
echo ${foo#def}
# succeed
echo ${foo#ab}
echo ${foo#def}
echo ${foo%fg}
echo ${foo%def}
+2 -3
View File
@@ -1,15 +1,14 @@
# expansions involving patterns
var='[hello'
echo "${var//[/}"
red='\[\e[0;31m\]'
echo "${red//\\[\\e/}"
printf "%s\n" "${red//\\[\\e/}"
foo="${red//\\[\\e/}"
# foo == [0;31m\]
echo "${foo//[0;31m\\/}"
printf "%s\n" "${foo//[0;31m\\/}"
echo "${var//[]/}"
echo "${red//[]/}"
+12
View File
@@ -9,3 +9,15 @@ recho $# "$1" "$2" "$3"
x=$c
recho "$x"
unset c c2 x
c=$'Y\1Y';
v=X${c}X;
recho X${c}X
recho "$v"
v=X$c
recho X$c
recho "$v"
+4 -4
View File
@@ -10,11 +10,11 @@ declare -p var | sed -n l
recho ${var@Q}
recho ${var@P}
echo ${var@A}
echo -E ${var@A}
unset array
array=( [$'x\001y\177z']=foo ) # should be error
echo ${array[@]@A}
echo -E ${array[@]@A}
unset array
declare -a array=([0]=$'x\001y\177z')
@@ -23,9 +23,9 @@ declare -p array
unset array
array=( "$var" )
recho ${array[@]}
echo ${array[@]@A}
echo -E ${array[@]@A}
unset array
declare -A array
array=( [$'x\001y\177z']=$'a\242b\002c' )
echo ${array[@]@A}
echo -E ${array[@]@A}
+9
View File
@@ -94,14 +94,23 @@ a ab
a
. ..
. .. a.log
*(foo)
*(foo|bar)
a.log
?(foo)
a.log
a.log
. ..
. ..
a.log
a.log
.x .y .z
a b c
.x .y .z a b c
a b c
a b c
a b c
a b c
.x .y .z a b c
.x .y .z a b c
*
+2
View File
@@ -374,4 +374,6 @@ ${THIS_SH} ./extglob3.sub
${THIS_SH} ./extglob4.sub
${THIS_SH} ./extglob5.sub
exit 0
+1 -1
View File
@@ -12,5 +12,5 @@ echo a!(x)
echo a*?(x)
echo a?(x)
builtin cd /
builtin cd $OLDPWD
rm -rf $TESTDIR
+5 -2
View File
@@ -1,5 +1,5 @@
shopt -s extglob
DIR=/tmp/extglob-$$
DIR=$TMPDIR/extglob-$$
mkdir $DIR
cd $DIR
@@ -7,15 +7,18 @@ touch a.log
echo *(.)
echo *(.)*
echo *(foo)
echo *(foo|bar)
echo ?(foo)*
echo ?(foo)
echo *(foo)*
echo @(|foo)*
echo *(foo).*
echo *(foo|bar).*
echo !(foo)*
echo !(foo|bar)*
cd $OLDPWD
rm -rf $DIR
+8 -1
View File
@@ -19,7 +19,14 @@ echo @(*|.!(|.)) # wrong, adds . and ..
echo @(*|@(f)) # ??
echo @(*|@(ff))
cd /
echo !(f)
echo !(f)!(f)
shopt -s dotglob
echo @(*|@(f))
echo @(*|@(ff))
cd $OLDPWD
rm -rf $GTDIR
[[ a = a*?(/)b ]] && echo bad match 1
+18
View File
@@ -0,0 +1,18 @@
# globignore extglob patterns containing colons -- problem until bash-4.2
: ${TMPDIR:=/tmp}
TESTDIR=$TMPDIR/bash-globignore-$$
[ -d "$TESTDIR" ] || mkdir "$TESTDIR"
cd "$TESTDIR" || exit 2
shopt -s extglob
GLOBIGNORE='+([^[:alnum:]]):@([-.,:; _]):[![:alnum:]]'
touch ';' '++'
echo *
rm ';' '++'
cd $OLDPWD
rmdir $TESTDIR
+1 -1
View File
@@ -2,7 +2,7 @@
getop () {
local OPTIND
local OPTIND=1
local OPTERR=1
echo getop: OPTERR=$OPTERR
+63 -1
View File
@@ -1,4 +1,66 @@
foo/bar foobar/bar
ok 1
ok 2
ok 3
ok 4
ok 5
b
argv[1] = <A£\B>
argv[1] = <A>
argv[1] = <B>
argv[1] = <a£\b>
0000000 141 243 134 142
0000004
ok 6
ok 7
invalid bracket expression
== LANG=C ==
[[:alpha:]
ok 1
[a
[[:alpha:]
ok 2
ok 3
== LANG=en_US.UTF-8 ==
[[:alpha:]
ok 1
[a
[[:alpha:]
ok 2
ok 3
invalid character class
== LANG=C ==
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
== LANG=en_US.UTF-8 ==
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
invalid collating symbols
== LANG=C ==
ok 1
ok 2
ok 3
ok 4
ok 5
== LANG=en_US.UTF-8 ==
ok 1
ok 2
ok 3
ok 4
ok 5
argv[1] = <a\?>
a?
argv[1] = <a\?>
a?
aa
argv[1] = <a>
argv[2] = <abc>
argv[3] = <abd>
@@ -13,7 +75,7 @@ argv[2] = <abc>
argv[3] = <abd>
argv[4] = <abe>
tmp/l1 tmp/l2 tmp/*4 tmp/l3
./glob.tests: line 44: no match: tmp/*4
./glob.tests: line 47: no match: tmp/*4
argv[1] = <bdir/>
argv[1] = <*>
argv[1] = <a*>
+5 -2
View File
@@ -4,15 +4,18 @@ export LC_COLLATE=C
#
expect()
{
echo expect "$@"
: # if needed, change me to echo expect "$@"
}
# First, a test that bash-2.01.1 fails
${THIS_SH} ./glob1.sub
${THIS_SH} ./glob2.sub
${THIS_SH} ./glob3.sub
${THIS_SH} ./glob4.sub
MYDIR=$PWD # save where we are
TESTDIR=/tmp/glob-test
TESTDIR=$TMPDIR/glob-test-$$
mkdir $TESTDIR
builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
rm -rf *
+5 -2
View File
@@ -1,7 +1,10 @@
# bash-2.01.1 failed this test
FN=/tmp/bash-glob.$$
: ${TMPDIR:=/var/tmp}
FN=$TMPDIR/bash-glob.$$
mkdir $FN
cd $FN
mkdir foo
mkdir foobar
touch foo/bar
@@ -10,5 +13,5 @@ chmod 311 foo foobar
echo f*/bar
chmod 777 foo foobar
cd /
cd $OLDPWD
rm -rf $FN
+44
View File
@@ -0,0 +1,44 @@
. ./test-glue-functions
var='ab\'
case $var in
ab\\) echo ok 1;;
*) echo bad 1;;
esac
case $var in
$var) echo ok 2;;
*) echo bad 2;;
esac
case $var in
'ab\') echo ok 3;;
*) echo bad 3;;
esac
[[ $var = $var ]] && echo ok 4
[[ $var = $'ab\134' ]] && echo ok 5
LC_ALL=zh_HK.big5hkscs
read a b c <<< $'\u3b1 b c\n'
echo $b
unset a b c
export alpha=$'\u3b1'
printf -v v 'A%sB' "$alpha"
recho "$v"
IFS=$alpha read a b c <<<"$v"
recho "$a"
recho "$b"
unset a b v
recho "a${alpha}b"
printf "%s" "a${alpha}b" | LC_ALL=C od -b | _intl_normalize_spaces
a=$'\u3b1'
[[ $a = $a ]] && echo ok 6
LC_ALL=zh_HK.big5hkscs ${THIS_SH} -c $'[[ \u3b1 = \u3b1 ]]' && echo ok 7
+123
View File
@@ -0,0 +1,123 @@
: ${TMPDIR:=/var/tmp}
cd $TMPDIR
matchfunc()
{
echo == LANG=$LANG ==
touch a p
echo [[:alpha:]
rm a p
case l in
[[:alpha:]) echo bad 1;;
*) echo ok 1;;
esac
touch '[a' '[x'
echo [[:alpha:]
rm '[a'
echo [[:alpha:]
rm '[x'
case [a in
[[:alpha:]) echo ok 2;;
*) echo bad 2;;
esac
case [x in
[[:alpha:]) echo bad 3;;
*) echo ok 3;;
esac
}
echo invalid bracket expression
export LANG=C
matchfunc
export LANG=en_US.UTF-8
matchfunc
unset -f matchfunc
matchfunc()
{
echo == LANG=$LANG ==
case a] in
[[:aleph:]]) echo bad 1;;
*) echo ok 1;;
esac
case a in
[[:aleph:]]) echo bad 2;;
*) echo ok 2;;
esac
case a] in
[[:"alpha":]]) echo bad 3;;
*) echo ok 3;;
esac
case a in
[[:"alpha":]]) echo bad 4;;
*) echo ok 4;;
esac
case a in
[abc[:foo:]]) echo ok 5;;
*) echo bad 5 ;;
esac
case a in
[[:foo:]abc]) echo ok 6;;
*) echo bad 6 ;;
esac
}
echo invalid character class
export LANG=C
matchfunc
export LANG=en_US.UTF-8
matchfunc
unset -f matchfunc
matchfunc()
{
echo == LANG=$LANG ==
case h in
[[.hyphen.]) echo bad 1;;
*) echo ok 1;;
esac
case - in
[[.hyphen.]]) echo ok 2;;
*) echo bad 2;;
esac
case slash in
[[.slash.]]) echo bad 3;;
*) echo ok 3;;
esac
case a in
[abc[.nonsense.]]) echo ok 4;;
*) echo bad 4 ;;
esac
case a in
[[.nonsense.]abc]) echo ok 5;;
*) echo bad 5 ;;
esac
}
echo invalid collating symbols
export LANG=C
matchfunc
export LANG=en_US.UTF-8
matchfunc
+13
View File
@@ -0,0 +1,13 @@
trap "rm 'a?' aa" EXIT
touch 'a?' aa
set -- a \?; IFS=\\; var=$*;
recho "$var"
unset IFS; printf "%s\n" ${var}
var='a\?'
recho "$var"
printf "%s\n" ${var}
var='a\a'
printf "%s\n" ${var}
+2 -1
View File
@@ -1,5 +1,6 @@
olddir=$PWD
EMPTY=/tmp/empty
: ${TMPDIR:=/var/tmp}
EMPTY=$TMPDIR/empty
shopt -s globstar
s()
+18 -10
View File
@@ -20,7 +20,7 @@ jkl mno
fff is a function
fff ()
{
ed /tmp/foo > /dev/null <<ENDOFINPUT
ed ${TMPDIR}/foo <<ENDOFINPUT > /dev/null
/^name/d
w
q
@@ -31,7 +31,7 @@ ENDOFINPUT
fff is a function
fff ()
{
ed /tmp/foo > /dev/null <<ENDOFINPUT
ed ${TMPDIR}/foo <<ENDOFINPUT > /dev/null
/^name/d
w
q
@@ -43,11 +43,11 @@ foo is a function
foo ()
{
echo;
cat <<END
cat <<END
bar
END
cat <<EOF
cat <<EOF
qux
EOF
@@ -59,13 +59,13 @@ qux
bar
qux
abc def geh
./heredoc3.sub: line 9: warning: here-document at line 7 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 10: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
= here is the text =
./heredoc3.sub: line 15: warning: here-document at line 13 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 16: warning: here-document at line 14 delimited by end-of-file (wanted `EOF')
this paren ) is not a problem
./heredoc3.sub: line 21: warning: here-document at line 19 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 22: warning: here-document at line 20 delimited by end-of-file (wanted `EOF')
these balanced parens ( ) are not a problem
./heredoc3.sub: line 27: warning: here-document at line 25 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 28: warning: here-document at line 26 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
@@ -82,8 +82,16 @@ end helloEND
hello
\END
end hello<NL>\END
./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
./heredoc3.sub: line 85: warning: here-document at line 83 delimited by end-of-file (wanted `EOF')
./heredoc3.sub: line 86: syntax error: unexpected end of file
heredoc1
EOF
Ok:0
argv[1] = <onetwo>
argv[2] = <threefour>
argv[1] = <two>
argv[2] = <threefi>
argv[3] = <ve>
comsub here-string
./heredoc.tests: line 105: warning: here-document at line 103 delimited by end-of-file (wanted `EOF')
hi
+7 -7
View File
@@ -59,22 +59,22 @@ cat <<- EOF
EOF
# check appending of text to file from here document
rm -f /tmp/bash-zzz
cat > /tmp/bash-zzz << EOF
rm -f ${TMPDIR}/bash-zzz
cat > ${TMPDIR}/bash-zzz << EOF
abc
EOF
cat >> /tmp/bash-zzz << EOF
cat >> ${TMPDIR}/bash-zzz << EOF
def ghi
jkl mno
EOF
cat /tmp/bash-zzz
rm -f /tmp/bash-zzz
cat ${TMPDIR}/bash-zzz
rm -f ${TMPDIR}/bash-zzz
# make sure command printing puts the here-document as the last redirection
# on the line, and the function export code preserves syntactic correctness
fff()
{
ed /tmp/foo <<ENDOFINPUT >/dev/null
ed ${TMPDIR}/foo <<ENDOFINPUT >/dev/null
/^name/d
w
q
@@ -90,8 +90,8 @@ ${THIS_SH} ./heredoc1.sub
# test heredocs in command substitutions
${THIS_SH} ./heredoc2.sub
${THIS_SH} ./heredoc3.sub
${THIS_SH} ./heredoc4.sub
echo $(
cat <<< "comsub here-string"
+8 -1
View File
@@ -1,4 +1,5 @@
SAVEPWD=$PWD
: ${TMPDIR:=/tmp}
cd $TMPDIR || echo "heredoc3.sub: cannot cd to $TMPDIR" >&2
text=$(cat <<EOF
@@ -69,7 +70,13 @@ cat <<END
hello
\END
END
echo end 'hello<NL>\END'
echo -E end 'hello<NL>\END'
# gprof
if [ -n "$GMON_OUT_PREFIX" ]; then
mv ${GMON_OUT_PREFIX}.[0-9]* "$SAVEPWD" >/dev/null 2>&1
fi
cd "$SAVEPWD"
# this has to be last -- results in a syntax error
# doesn't currently parse because EOF is not on a line by itself -- should it?
+12
View File
@@ -0,0 +1,12 @@
cat <<EO`true`F
heredoc1
EO`false`F
EO`true`F
echo Ok:$?
one=one
four=four
five='fi ve'
recho $one`echo two three`$four
recho `echo two three`$five
+48 -2
View File
@@ -8,7 +8,7 @@ echo $BASH_VERSION
2 /bin/sh -c 'echo this is $0'
3 ls
4 echo $BASH_VERSION
5 HISTFILE=/tmp/newhistory
5 HISTFILE=$TMPDIR/newhistory
6 echo line 2 for history
echo line 2 for history
echo line 2 for history
@@ -19,7 +19,7 @@ line 2 for history
2 /bin/sh -c 'echo this is $0'
3 ls
4 echo $BASH_VERSION
5 HISTFILE=/tmp/newhistory
5 HISTFILE=$TMPDIR/newhistory
6 echo line 2 for history
7 set -H
8 echo line 2 for history
@@ -181,6 +181,15 @@ echo g
g
eval echo "echo g"
echo g
h
echo \!\! `echo echo h`
!! echo h
i
echo echo i `echo echo i`
echo i echo i
j
echo `echo j` echo j
j echo j
a
cat < <(echo echo a)
echo a
@@ -194,3 +203,40 @@ d
e
! !
./histexp4.sub: line 20: !': event not found
/tmp/Step1
echo /$(echo tmp)/Step1
/tmp/Step1
echo /<(echo tmp)/Step1 > /dev/null
/tmp/Step1
echo $(echo /tmp)/Step1
/tmp/Step1
echo <(echo /tmp)/Step1 > /dev/null
/+(one|two|three)/Step1
echo /+(one|two|three)/Step1
/+(one|two|three)/Step1
/*(tmp|dev|usr)/Step1
echo /*(tmp|dev|usr)/Step1
/*(tmp|dev|usr)/Step1
+(/one|/two|/three)/Step1
echo +(/one|/two|/three)/Step1
+(/one|/two|/three)/Step1
*(/tmp|/dev|/usr)/Step1
echo *(/tmp|/dev|/usr)/Step1
*(/tmp|/dev|/usr)/Step1
one
echo echo one
echo one
echo one
echo one
1 set -o histexpand
2 echo one
3 for f in a b c; do echo echo one; done
4 history
two
echo echo two
echo two
echo two
echo two
1 echo two
2 for f in a b c; do echo echo two; done
3 history
+4 -2
View File
@@ -1,6 +1,6 @@
LC_ALL=C
LANG=C
trap 'rm /tmp/newhistory' 0
trap 'rm $TMPDIR/newhistory' 0
file=bax
histchars='!^#' # make sure history comment char is set correctly
@@ -25,7 +25,7 @@ history -p '!!:z'
history
HISTFILE=/tmp/newhistory
HISTFILE=$TMPDIR/newhistory
history -a
history -w
@@ -140,3 +140,5 @@ ${THIS_SH} ./histexp1.sub
${THIS_SH} ./histexp2.sub
${THIS_SH} ./histexp3.sub
${THIS_SH} ./histexp4.sub
${THIS_SH} ./histexp5.sub
${THIS_SH} ./histexp6.sub
+9
View File
@@ -31,5 +31,14 @@ echo "!!"
echo g
eval echo "!!"
echo h
echo \!\! `echo !!`
echo i
echo !! `echo !!`
echo j
echo `echo j` !!
set +o history
rm -f $HISTFILE # just in case
+28
View File
@@ -0,0 +1,28 @@
set -o history
set -o histexpand
# command and process substitutions should be tokenized as a single word
echo /$(echo tmp)/Step1
echo !:*
echo /<(echo tmp)/Step1 >/dev/null
echo !:*
# same tests at the beginning of a word
echo $(echo /tmp)/Step1
echo !:*
echo <(echo /tmp)/Step1 >/dev/null
echo !:*
# so should shell extended glob patterns
shopt -s extglob
echo /+(one|two|three)/Step1
echo !:*
echo /*(tmp|dev|usr)/Step1
echo !:*
# same tests at the beginning of a word
echo +(/one|/two|/three)/Step1
echo !:*
echo *(/tmp|/dev|/usr)/Step1
echo !:*
+24
View File
@@ -0,0 +1,24 @@
unset HISTIGNORE
HISTFILE=$TMPDIR/bashhist-$$
set -o history
set -o histexpand
echo one
for f in a b c; do
echo !!
done
history
history -c
echo two
for f in a b c; do
echo !-1
done
history
set +o history
rm -f $HISTFILE
+45 -11
View File
@@ -36,13 +36,13 @@ echo line for history
echo line for history
displaying $HISTFILE after history -a
echo line for history
HISTFILE=/tmp/newhistory
HISTFILE=$TMPDIR/newhistory
1 for i in one two three; do echo $i; done
2 /bin/sh -c 'echo this is $0'
3 ls
4 echo $BASH_VERSION
5 echo line for history
6 HISTFILE=/tmp/newhistory
6 HISTFILE=$TMPDIR/newhistory
7 echo displaying \$HISTFILE after history -a
8 cat $HISTFILE
for i in one two three; do echo $i; done
@@ -50,7 +50,7 @@ for i in one two three; do echo $i; done
ls
echo $BASH_VERSION
echo line for history
HISTFILE=/tmp/newhistory
HISTFILE=$TMPDIR/newhistory
echo displaying \$HISTFILE after history -a
cat $HISTFILE
1 for i in one two three; do echo $i; done
@@ -58,7 +58,7 @@ cat $HISTFILE
3 ls
4 echo $BASH_VERSION
5 echo line for history
6 HISTFILE=/tmp/newhistory
6 HISTFILE=$TMPDIR/newhistory
7 echo displaying \$HISTFILE after history -a
8 cat $HISTFILE
9 echo line 2 for history
@@ -69,7 +69,7 @@ echo line 2 for history
3 ls
4 echo $BASH_VERSION
5 echo line for history
6 HISTFILE=/tmp/newhistory
6 HISTFILE=$TMPDIR/newhistory
7 echo displaying \$HISTFILE after history -a
8 cat $HISTFILE
9 echo line 2 for history
@@ -80,7 +80,7 @@ echo line 2 for history
line 2 for history
4 echo $BASH_VERSION
5 echo line for history
6 HISTFILE=/tmp/newhistory
6 HISTFILE=$TMPDIR/newhistory
7 echo displaying \$HISTFILE after history -a
8 cat $HISTFILE
9 echo line 2 for history
@@ -94,10 +94,10 @@ line 2 for history
17 unset HISTFILE
4 echo $BASH_VERSION
5 echo line for history
6 HISTFILE=/tmp/newhistory
6 HISTFILE=$TMPDIR/newhistory
7 echo displaying \$HISTFILE after history -a
8 cat $HISTFILE
./history.tests: line 75: fc: history specification out of range
./history.tests: line 76: fc: history specification out of range
14 set -H
15 echo line 2 for history
16 unset HISTSIZE
@@ -107,7 +107,7 @@ echo xx xb xc
xx xb xc
echo 44 48 4c
44 48 4c
./history.tests: line 90: fc: no command found
./history.tests: line 91: fc: no command found
aa
bb
cc
@@ -140,7 +140,41 @@ three
one
two
three
4.4
5.0
echo ${BASH_VERSION%\.*}
4.4
5.0
echo ${BASH_VERSION%\.*}
a
b
c
d
e
1 echo a
2 echo b
3 echo c
4 echo d
5 echo e
1 echo a
2 echo e
f
g
h
i
1 echo a
2 echo e
3 echo f
4 echo g
5 echo h
./history3.sub: line 27: history: 16: history position out of range
./history3.sub: line 28: history: 200: history position out of range
./history3.sub: line 29: history: -20: history position out of range
./history3.sub: line 30: history: -50: history position out of range
./history3.sub: line 31: history: 5-0xaf: history position out of range
1 echo a
2 echo e
3 echo f
4 echo g
5 echo h
+4 -2
View File
@@ -1,4 +1,4 @@
trap 'rm /tmp/newhistory' 0
trap 'rm $TMPDIR/newhistory' 0
# bad options
history -x
@@ -20,6 +20,7 @@ HISTFILE=history.list
HISTCONTROL=ignoreboth
HISTIGNORE='&:history*:fc*'
HISTSIZE=32
export HISTIGNORE
shopt -s cmdhist
set -o history
@@ -39,7 +40,7 @@ history -p '!!'
fc -nl
HISTFILE=/tmp/newhistory
HISTFILE=$TMPDIR/newhistory
history -a
echo displaying \$HISTFILE after history -a
cat $HISTFILE
@@ -112,3 +113,4 @@ ${THIS_SH} ./history1.sub
rm -f $TMPDIR/foohist-*
${THIS_SH} ./history2.sub
${THIS_SH} ./history3.sub
+36
View File
@@ -0,0 +1,36 @@
: ${TMPDIR:=/tmp}
set -o history
HISTFILE=$TMPDIR/history-$$
history -c
echo a
echo b
echo c
echo d
echo e
history ; echo
history -d 2-4
history
echo f
echo g
echo h
echo i
history -d 6--1
history ; echo
history -d 16-40
history -d 1-200
history -d -20-50
history -d 1--50
history -d 5-0xaf
history ; echo
unset HISTFILE
exit 0
+2
View File
@@ -8,3 +8,5 @@ a:b:c:d:e
a:b:c:d:e
a b c d e
a b c d e
argv[1] = <file>
argv[1] = <*>
+2
View File
@@ -59,3 +59,5 @@ IFS=: export x
echo $x
IFS="$DEFIFS"
${THIS_SH} ./ifs1.sub
+14
View File
@@ -0,0 +1,14 @@
: ${TMPDIR:=/tmp}
dir=bashtest-$$
mkdir $TMPDIR/$dir || exit 1
touch $TMPDIR/$dir/file || exit 2
cd $TMPDIR/$dir || exit 3
IFS='?*[]'
recho *
recho "*"
cd $OLDPWD
rm -rf $TMPDIR/$dir
+3 -2
View File
@@ -50,7 +50,8 @@ Passed all 1378 Unicode tests
0000003
0000000 101 040 302 243 040 305 222 012
0000010
./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
./unicode3.sub: line 5: $'5\247@3\231+\306S8\237\242\352\263': command not found
./unicode3.sub: line 7: 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'
+ set +x
+21 -20
View File
@@ -16,31 +16,32 @@ Waiting for job 6
job 6 returns 0
Waiting for job 7
job 7 returns 0
[1] Running sleep 5 &
[2] Running sleep 5 &
[3] Running sleep 5 &
[4]- Running sleep 5 &
[5]+ Running ( sleep 5; exit 4 ) &
[1] Running sleep 2 &
[2] Running sleep 2 &
[3] Running sleep 2 &
[4]- Running sleep 2 &
[5]+ Running ( sleep 2; exit 4 ) &
4
0
i killed it
12
[1]- Running sleep 20 &
[3]+ Running sleep 20 &
child1 exit status 0
0
./jobs.tests: line 22: wait: %1: no such job
./jobs.tests: line 27: fg: no job control
./jobs.tests: line 25: wait: %1: no such job
./jobs.tests: line 30: fg: no job control
wait-for-pid
wait-errors
./jobs.tests: line 40: wait: `1-1': not a pid or valid job spec
./jobs.tests: line 41: wait: `-4': not a pid or valid job spec
./jobs.tests: line 43: wait: `1-1': not a pid or valid job spec
./jobs.tests: line 44: wait: `-4': not a pid or valid job spec
wait-for-background-pids
async list wait-for-background-pids
async list wait for child
forked
wait-when-no-children
wait-for-job
./jobs.tests: line 63: wait: %2: no such job
./jobs.tests: line 66: wait: %2: no such job
127
async list wait-for-job
forked
@@ -53,19 +54,19 @@ sleep 5
fg-bg 4
sleep 5
fg-bg 5
./jobs.tests: line 90: fg: %2: no such job
./jobs.tests: line 91: bg: job 1 already in background
./jobs.tests: line 93: fg: %2: no such job
./jobs.tests: line 94: bg: job 1 already in background
fg-bg 6
./jobs.tests: line 98: fg: -s: invalid option
./jobs.tests: line 101: fg: -s: invalid option
fg: usage: fg [job_spec]
./jobs.tests: line 99: bg: -s: invalid option
./jobs.tests: line 102: bg: -s: invalid option
bg: usage: bg [job_spec ...]
./jobs.tests: line 104: disown: -s: invalid option
./jobs.tests: line 107: disown: -s: invalid option
disown: usage: disown [-h] [-ar] [jobspec ... | pid ...]
./jobs.tests: line 108: disown: %1: no such job
./jobs.tests: line 111: disown: %2: no such job
./jobs.tests: line 111: disown: %1: no such job
./jobs.tests: line 114: disown: %2: no such job
wait-for-non-child
./jobs.tests: line 114: wait: pid 1 is not a child of this shell
./jobs.tests: line 117: wait: pid 1 is not a child of this shell
127
3 -- 1 2 3 -- 1 - 2 - 3
[1] Running sleep 300 &
@@ -75,8 +76,8 @@ running jobs:
[1] Running sleep 300 &
[2]- Running sleep 350 &
[3]+ Running sleep 400 &
./jobs.tests: line 131: kill: %4: no such job
./jobs.tests: line 133: jobs: %4: no such job
./jobs.tests: line 134: kill: %4: no such job
./jobs.tests: line 136: jobs: %4: no such job
current job:
[3]+ Running sleep 400 &
previous job:
+3
View File
@@ -15,6 +15,9 @@ ${THIS_SH} ./jobs4.sub
# test out wait -n framework
${THIS_SH} ./jobs5.sub
# test out wait -f framework
${THIS_SH} ./jobs6.sub
jobs
echo $?
+1 -1
View File
@@ -2,7 +2,7 @@
set -m
sleep 60 &
FN=/tmp/jobs-pid.$$
FN=$TMPDIR/jobs-pid.$$
pid1=$!
jobs -p %+ > $FN
+5 -5
View File
@@ -1,12 +1,12 @@
# test being able to use job control notation in jobs/kill/wait without
# job control active, as the SUS requires
sleep 5 &
sleep 2 &
sleep 5 &
sleep 5 &
sleep 5 &
(sleep 5 ; exit 4) &
sleep 2 &
sleep 2 &
sleep 2 &
(sleep 2 ; exit 4) &
jobs
+14
View File
@@ -0,0 +1,14 @@
# framework to test `wait -f' which forces wait until a job exits
set -o monitor
sleep 5 &
child1=$!
( sleep 1; kill -STOP $child1 ; sleep 1 ; kill -CONT $child1 )&
child2=$!
wait -f %1
echo child1 exit status $?
wait $child2
exit 0
+2 -2
View File
@@ -152,7 +152,7 @@ b1()
b2()
{
recho $*
recho $#
recho ${#}
}
expect '<1>'
@@ -414,7 +414,7 @@ recho ${#}
expect '<5>'
recho ${#?:-xyz}
shift $#
shift ${#}
expect '<0>'
recho ${#:-foo}

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