commit bash-20070405 snapshot

This commit is contained in:
Chet Ramey
2011-12-07 09:06:13 -05:00
parent d3ad40dee6
commit e6598ba488
36 changed files with 20242 additions and 362 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+64 -4
View File
@@ -152,10 +152,10 @@ for case if then else
12 14 16 18 20
4414758999202
aaa bbb
./array.tests: line 285: syntax error near unexpected token `<>'
./array.tests: line 285: `metas=( <> < > ! )'
./array.tests: line 286: syntax error near unexpected token `<>'
./array.tests: line 286: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
./array.tests: line 287: syntax error near unexpected token `<>'
./array.tests: line 287: `metas=( <> < > ! )'
./array.tests: line 288: syntax error near unexpected token `<>'
./array.tests: line 288: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
abc 3
case 4
abc case if then else 5
@@ -206,3 +206,63 @@ t
e
9
2
a b c
argv[1] = <"-iname '"a>
argv[2] = <"-iname '"b>
argv[3] = <"-iname '"c>
'hey'
hey
''hey
'hey'
argv[1] = <c>
argv[2] = <d>
argv[3] = <e>
argv[4] = <f>
argv[1] = <c d>
argv[2] = <e f>
argv[1] = <c d>
argv[2] = <e f>
argv[1] = <c d>
argv[2] = <e f>
argv[1] = <"-iname '"abc>
argv[2] = <"-iname '"def>
argv[1] = <-iname 'abc>
argv[2] = <-iname 'def>
argv[1] = <-iname \'abc>
argv[2] = <-iname \'def>
argv[1] = <-iname>
argv[2] = <'abc>
argv[3] = <-iname>
argv[4] = <'def>
argv[1] = <"-iname '"abc>
argv[2] = <"-iname '"def>
argv[1] = <-iname 'abc>
argv[2] = <-iname 'def>
*.* OK
1
a1 2 3c
argv[1] = <var with spaces>
argv[1] = <var with spaces>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <var with spacesab>
argv[2] = <cd>
argv[3] = <ef>
2
argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
+6 -30
View File
@@ -253,6 +253,8 @@ foo=([10]="bar")
echo ${foo[0]}
rm 1=bar
cd $OLDPWD
foo=(a b c d e f g)
echo ${foo[@]}
@@ -372,34 +374,8 @@ declare -a x=($0)
declare -a x=(\$0)
echo "${x[@]}"
: ${TMPDIR:=/tmp}
# tests for bash-3.1 problems
${THIS_SH} ./array5.sub
mkdir $TMPDIR/bash-test-$$
cd $TMPDIR/bash-test-$$
trap "cd / ; rm -rf $TMPDIR/bash-test-$$" 0 1 2 3 6 15
touch '[3]=abcde'
touch r s t u v
declare -a x=(*)
echo ${x[3]}
echo ${x[@]}
unset x
x=(a b c d e)
echo ${x[*]: -1}
unset x[4]
unset x[2]
x[9]='9'
echo ${x[*]: -1}
TOOLKIT=(1 2 3 4 5 6 7 8 9 10)
ARRAY="1"
echo ${TOOLKIT["$ARRAY"]}
# tests for post-bash-3.2 problems, most fixed in bash-3.2 patches
${THIS_SH} ./array6.sub
+34
View File
@@ -0,0 +1,34 @@
: ${TMPDIR:=/tmp}
mkdir $TMPDIR/bash-test-$$
cd $TMPDIR/bash-test-$$
trap "cd / ; rm -rf $TMPDIR/bash-test-$$" 0 1 2 3 6 15
touch '[3]=abcde'
touch r s t u v
declare -a x=(*)
echo ${x[3]}
echo ${x[@]}
unset x
x=(a b c d e)
echo ${x[*]: -1}
unset x[4]
unset x[2]
x[9]='9'
echo ${x[*]: -1}
TOOLKIT=(1 2 3 4 5 6 7 8 9 10)
ARRAY="1"
echo ${TOOLKIT["$ARRAY"]}
exit 0
+109
View File
@@ -0,0 +1,109 @@
# test cases for array quoting and escaping fixed post bash-3.2-release
oIFS="$IFS"
a=(a b c)
echo ${a[@]}
a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
echo "${dbg-"'hey'"}"
echo "${dbg-"hey"}"
echo "${dbg-'"'hey}"
echo "${dbg-'"hey'}"
unset a a2
IFS=
a2=(${a[@]/#/"-iname '"})
recho "${a2[@]}"
IFS="$oIFS"
unset a a2
a=('a b' 'c d' 'e f')
recho ${a[@]:1:2}
recho "${a[@]:1:2}"
IFS=
recho ${a[@]:1:2}
recho "${a[@]:1:2}"
IFS="$oIFS"
unset a a2
a=(abc def)
# Prevent word splitting
#IFS=
a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
eval a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
a2=("${a[@]/#/-iname \'}")
recho "${a2[@]}"
eval a2=("${a[@]/#/-iname \'}")
recho "${a2[@]}"
set -- abc def
a2=("${@/#/"-iname '"}")
recho "${a2[@]}"
eval a2=("${@/#/"-iname '"}")
recho "${a2[@]}"
unset a a2
IFS=
pat=('*.*')
case $(ls ${pat[@]} 2>/dev/null) in
'') echo '*.* BAD' ;;
*) echo '*.* OK' ;;
esac
IFS="$oIFS"
unset a a2 pat
IFS=
s='abc'
set - ${s/b/1 2 3}
echo $#
echo "$1"
IFS="$oIFS"
unset s
set -- ab cd ef
foo="var with spaces"
IFS=
recho $foo
recho "$foo"
recho ${foo}"$@"
recho ${foo}$@
array=(ab cd ef)
recho ${foo}"${array[@]}"
recho ${foo}${array[@]}
recho $(echo $foo)"$@"
recho $(echo $foo)$@
a=('word1 with spaces' 'word2 with spaces')
set - ${a[@]/word/element}
echo $#
recho "$@"
recho $@
IFS="$oIFS"
unset a a2 array foo
+123
View File
@@ -0,0 +1,123 @@
# test cases for array quoting and escaping fixed post bash-3.2-release
oIFS="$IFS"
a=(a b c)
echo ${a[@]}
a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
echo "${dbg-"'hey'"}"
echo "${dbg-"hey"}"
echo "${dbg-'"'hey}"
echo "${dbg-'"hey'}"
unset a a2
IFS=
a2=(${a[@]/#/"-iname '"})
recho "${a2[@]}"
IFS="$oIFS"
unset a a2
a=('a b' 'c d' 'e f')
recho ${a[@]:1:2}
recho "${a[@]:1:2}"
IFS=
recho ${a[@]:1:2}
recho "${a[@]:1:2}"
IFS="$oIFS"
unset a a2
a=(abc def)
# Prevent word splitting
#IFS=
a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
eval a2=("${a[@]/#/"-iname '"}")
recho "${a2[@]}"
a2=("${a[@]/#/-iname \'}")
recho "${a2[@]}"
eval a2=("${a[@]/#/-iname \'}")
recho "${a2[@]}"
set -- abc def
a2=("${@/#/"-iname '"}")
recho "${a2[@]}"
eval a2=("${@/#/"-iname '"}")
recho "${a2[@]}"
unset a a2
IFS=
pat=('*.*')
case $(ls ${pat[@]} 2>/dev/null) in
'') echo '*.* BAD' ;;
*) echo '*.* OK' ;;
esac
IFS="$oIFS"
unset a a2 pat
IFS=
s='abc'
set - ${s/b/1 2 3}
echo $#
echo "$1"
IFS="$oIFS"
unset s
set -- ab cd ef
foo="var with spaces"
IFS=
recho $foo
recho "$foo"
recho ${foo}"$@"
recho ${foo}$@
array=(ab cd ef)
recho ${foo}"${array[@]}"
recho ${foo}${array[@]}
recho $(echo $foo)"$@"
recho $(echo $foo)$@
a=('word1 with spaces' 'word2 with spaces')
set - ${a[@]/word/element}
echo $#
recho "$@"
recho $@
IFS="$oIFS"
unset a a2 array foo
a=$'ab\001cd\001ef'
recho $a
recho "$a"
recho $(echo $a)
recho $(echo "$a")
# XXX - this doesn't work right until post-bash-3.2
IFS=$'\001'
recho $a
IFS=$'\001' recho "$a"
+11
View File
@@ -145,3 +145,14 @@ argv[4] = <d>
argv[5] = <e>
a?b?c
a b c
argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^?>
argv[1] = <^A>
argv[2] = <^?>
argv[1] = <^A^?>
argv[1] = <^A^?^A^?>
argv[1] = <^A^A^?>
+382
View File
@@ -0,0 +1,382 @@
#
# A suite of tests for bash word expansions
#
# This tests parameter and variable expansion, with an empahsis on
# proper quoting behavior.
#
# Chet Ramey
#
# If you comment out the body of this function, you can do a diff against
# `expansion-tests.right' to see if the shell is behaving correctly
#
expect()
{
echo expect "$@"
}
# Test the substitution quoting characters (CTLESC and CTLNUL) in different
# combinations
expect "<^A>"
recho `echo ''`
expect "<^A>"
recho `echo ""`
expect "<^B>"
recho `echo ''`
expect "<^B>"
recho `echo ""`
expect "<^A>"
recho `echo `
expect "<^B>"
recho `echo `
# Test null strings without variable expansion
expect "<abcdefgh>"
recho abcd""efgh
expect "<abcdefgh>"
recho abcd''efgh
expect "<abcdefgh>"
recho ""abcdefgh
expect "<abcdefgh>"
recho ''abcdefgh
expect "<abcd>"
recho abcd""
expect "<abcd>"
recho abcd''
# Test the quirky behavior of $@ in ""
expect nothing
recho "$@"
expect "< >"
recho " $@"
expect "<-->"
recho "-${@}-"
# Test null strings with variable expansion that fails
expect '<>'
recho $xxx""
expect '<>'
recho ""$xxx
expect '<>'
recho $xxx''
expect '<>'
recho ''$xxx
expect '<>'
recho $xxx""$yyy
expect '<>'
recho $xxx''$yyy
# Test null strings with variable expansion that succeeds
xxx=abc
yyy=def
expect '<abc>'
recho $xxx""
expect '<abc>'
recho ""$xxx
expect '<abc>'
recho $xxx''
expect '<abc>'
recho ''$xxx
expect '<abcdef>'
recho $xxx""$yyy
expect '<abcdef>'
recho $xxx''$yyy
unset xxx yyy
# Test the unquoted special quoting characters
expect "<^A>"
recho 
expect "<^B>"
recho 
expect "<^A>"
recho ""
expect "<^B>"
recho ""
expect "<^A>"
recho ''
expect "<^B>"
recho ''
# Test expansion of a variable that is unset
expect nothing
recho $xxx
expect '<>'
recho "$xxx"
expect nothing
recho "$xxx${@}"
# Test empty string expansion
expect '<>'
recho ""
expect '<>'
recho ''
# Test command substitution with (disabled) history substitution
expect '<Hello World!>'
# set +H
recho "`echo \"Hello world!\"`"
# Test some shell special characters
expect '<`>'
recho "\`"
expect '<">'
recho "\""
expect '<\^A>'
recho "\"
expect '<\$>'
recho "\\$"
expect '<\\>'
recho "\\\\"
# This should give argv[1] = a argv[2] = b
expect '<a> <b>'
FOO=`echo 'a b' | tr ' ' '\012'`
recho $FOO
# This should give argv[1] = ^A argv[2] = ^B
expect '<^A> <^B>'
FOO=`echo ' ' | tr ' ' '\012'`
recho $FOO
# Test quoted and unquoted globbing characters
expect '<**>'
recho "*"*
expect '<\.\./*/>'
recho "\.\./*/"
# Test patterns that come up when the shell quotes funny character
# combinations
expect '<^A^B^A^B>'
recho ''
expect '<^A^A>'
recho ''
expect '<^A^B>'
recho ''
expect '<^A^A^B>'
recho ''
# More tests of "$@"
set abc def ghi jkl
expect '< abc> <def> <ghi> <jkl >'
recho " $@ "
expect '< abc> <def> <ghi> <jkl >'
recho "${1+ $@ }"
set abc def ghi jkl
expect '<--abc> <def> <ghi> <jkl-->'
recho "--$@--"
set "a b" cd ef gh
expect '<a b> <cd> <ef> <gh>'
recho ${1+"$@"}
expect '<a b> <cd> <ef> <gh>'
recho ${foo:-"$@"}
expect '<a b> <cd> <ef> <gh>'
recho "${@}"
expect '< >'
recho " "
expect '< - >'
recho " - "
# Test combinations of different types of quoting in a fully-quoted string
# (so the WHOLLY_QUOTED tests fail and it doesn't get set)
expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
# Test the various Posix parameter expansions
expect '<foo bar>'
recho "${x:-$(echo "foo bar")}"
expect '<foo> <bar>'
recho ${x:-$(echo "foo bar")}
unset X
expect '<abc>'
recho ${X:=abc}
expect '<abc>'
recho $X
set a b c
expect '<posix>'
recho ${3:+posix}
POSIX=/usr/posix
expect '<10>'
recho ${#POSIX}
# remove shortest trailing match
x=file.c
expect '<file.o>'
recho ${x%.c}.o
# remove longest trailing match
x=posix/src/std
expect '<posix>'
recho ${x%%/*}
# remove shortest leading pattern
x=$HOME/src/cmd
expect '</src/cmd>'
recho ${x#$HOME}
# remove longest leading pattern
x=/one/two/three
expect '<three>'
recho ${x##*/}
# pattern removal of patterns that don't match
z=abcdef
expect '<abcdef>'
recho ${z#xyz}
expect '<abcdef>'
recho ${z##xyz}
expect '<abcdef>'
recho ${z%xyz}
expect '<abcdef>'
recho ${z%%xyz}
# Command substitution and the quirky differences between `` and $()
expect '<\$x>'
recho '\$x'
expect '<$x>'
recho `echo '\$x'`
expect '<\$x>'
recho $(echo '\$x')
# The difference between $* "$*" and "$@"
set "abc" "def ghi" "jkl"
expect '<abc> <def> <ghi> <jkl>'
recho $*
expect '<abc def ghi jkl>'
recho "$*"
OIFS="$IFS"
IFS=":$IFS"
# The special behavior of "$*", using the first character of $IFS as separator
expect '<abc:def ghi:jkl>'
recho "$*"
IFS="$OIFS"
expect '<abc> <def ghi> <jkl>'
recho "$@"
expect '<xxabc> <def ghi> <jklyy>'
recho "xx$@yy"
expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
recho "$@$@"
foo=abc
bar=def
expect '<abcdef>'
recho "$foo""$bar"
unset foo
set $foo bar '' xyz "$foo" abc
expect '<bar> <> <xyz> <> <abc>'
recho "$@"
# More tests of quoting and deferred evaluation
foo=10 x=foo
y='$'$x
expect '<$foo>'
recho $y
eval y='$'$x
expect '<10>'
recho $y
# case statements
NL='
'
x='ab
cd'
expect '<newline expected>'
case "$x" in
*$NL*) recho "newline expected" ;;
esac
expect '<got it>'
case \? in
*"?"*) recho "got it" ;;
esac
expect '<got it>'
case \? in
*\?*) recho "got it" ;;
esac
set one two three four five
expect '<one> <three> <five>'
recho $1 $3 ${5} $8 ${9}
# length tests on positional parameters and some special parameters
expect '<5> <5>'
recho $# ${#}
expect '<3>'
recho ${#1}
expect '<1>'
recho ${##}
expect '<1>'
recho ${#?}
expect '<5>'
recho ${#@}
expect '<5>'
recho ${#*}
expect '<5>'
recho "${#@}"
expect '<5>'
recho "${#*}"
expect '<42>'
recho $((28 + 14))
expect '<26>'
recho $[ 13 * 2 ]
expect '<\>'
recho `echo \\\\`
expect '<~>'
recho '~'
expect nothing
recho $!
expect nothing
recho ${!}
# test word splitting of assignment statements not preceding a command
a="a b c d e"
declare b=$a
expect '<a> <b> <c> <d> <e>'
recho $b
a="a?b?c"
echo ${a//\\?/ }
echo ${a//\?/ }
${THIS_SH} ./exp1.sub
+380
View File
@@ -0,0 +1,380 @@
#
# A suite of tests for bash word expansions
#
# This tests parameter and variable expansion, with an empahsis on
# proper quoting behavior.
#
# Chet Ramey
#
# If you comment out the body of this function, you can do a diff against
# `expansion-tests.right' to see if the shell is behaving correctly
#
expect()
{
echo expect "$@"
}
# Test the substitution quoting characters (CTLESC and CTLNUL) in different
# combinations
expect "<^A>"
recho `echo ''`
expect "<^A>"
recho `echo ""`
expect "<^B>"
recho `echo ''`
expect "<^B>"
recho `echo ""`
expect "<^A>"
recho `echo `
expect "<^B>"
recho `echo `
# Test null strings without variable expansion
expect "<abcdefgh>"
recho abcd""efgh
expect "<abcdefgh>"
recho abcd''efgh
expect "<abcdefgh>"
recho ""abcdefgh
expect "<abcdefgh>"
recho ''abcdefgh
expect "<abcd>"
recho abcd""
expect "<abcd>"
recho abcd''
# Test the quirky behavior of $@ in ""
expect nothing
recho "$@"
expect "< >"
recho " $@"
expect "<-->"
recho "-${@}-"
# Test null strings with variable expansion that fails
expect '<>'
recho $xxx""
expect '<>'
recho ""$xxx
expect '<>'
recho $xxx''
expect '<>'
recho ''$xxx
expect '<>'
recho $xxx""$yyy
expect '<>'
recho $xxx''$yyy
# Test null strings with variable expansion that succeeds
xxx=abc
yyy=def
expect '<abc>'
recho $xxx""
expect '<abc>'
recho ""$xxx
expect '<abc>'
recho $xxx''
expect '<abc>'
recho ''$xxx
expect '<abcdef>'
recho $xxx""$yyy
expect '<abcdef>'
recho $xxx''$yyy
unset xxx yyy
# Test the unquoted special quoting characters
expect "<^A>"
recho 
expect "<^B>"
recho 
expect "<^A>"
recho ""
expect "<^B>"
recho ""
expect "<^A>"
recho ''
expect "<^B>"
recho ''
# Test expansion of a variable that is unset
expect nothing
recho $xxx
expect '<>'
recho "$xxx"
expect nothing
recho "$xxx${@}"
# Test empty string expansion
expect '<>'
recho ""
expect '<>'
recho ''
# Test command substitution with (disabled) history substitution
expect '<Hello World!>'
# set +H
recho "`echo \"Hello world!\"`"
# Test some shell special characters
expect '<`>'
recho "\`"
expect '<">'
recho "\""
expect '<\^A>'
recho "\"
expect '<\$>'
recho "\\$"
expect '<\\>'
recho "\\\\"
# This should give argv[1] = a argv[2] = b
expect '<a> <b>'
FOO=`echo 'a b' | tr ' ' '\012'`
recho $FOO
# This should give argv[1] = ^A argv[2] = ^B
expect '<^A> <^B>'
FOO=`echo ' ' | tr ' ' '\012'`
recho $FOO
# Test quoted and unquoted globbing characters
expect '<**>'
recho "*"*
expect '<\.\./*/>'
recho "\.\./*/"
# Test patterns that come up when the shell quotes funny character
# combinations
expect '<^A^B^A^B>'
recho ''
expect '<^A^A>'
recho ''
expect '<^A^B>'
recho ''
expect '<^A^A^B>'
recho ''
# More tests of "$@"
set abc def ghi jkl
expect '< abc> <def> <ghi> <jkl >'
recho " $@ "
expect '< abc> <def> <ghi> <jkl >'
recho "${1+ $@ }"
set abc def ghi jkl
expect '<--abc> <def> <ghi> <jkl-->'
recho "--$@--"
set "a b" cd ef gh
expect '<a b> <cd> <ef> <gh>'
recho ${1+"$@"}
expect '<a b> <cd> <ef> <gh>'
recho ${foo:-"$@"}
expect '<a b> <cd> <ef> <gh>'
recho "${@}"
expect '< >'
recho " "
expect '< - >'
recho " - "
# Test combinations of different types of quoting in a fully-quoted string
# (so the WHOLLY_QUOTED tests fail and it doesn't get set)
expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
# Test the various Posix parameter expansions
expect '<foo bar>'
recho "${x:-$(echo "foo bar")}"
expect '<foo> <bar>'
recho ${x:-$(echo "foo bar")}
unset X
expect '<abc>'
recho ${X:=abc}
expect '<abc>'
recho $X
set a b c
expect '<posix>'
recho ${3:+posix}
POSIX=/usr/posix
expect '<10>'
recho ${#POSIX}
# remove shortest trailing match
x=file.c
expect '<file.o>'
recho ${x%.c}.o
# remove longest trailing match
x=posix/src/std
expect '<posix>'
recho ${x%%/*}
# remove shortest leading pattern
x=$HOME/src/cmd
expect '</src/cmd>'
recho ${x#$HOME}
# remove longest leading pattern
x=/one/two/three
expect '<three>'
recho ${x##*/}
# pattern removal of patterns that don't match
z=abcdef
expect '<abcdef>'
recho ${z#xyz}
expect '<abcdef>'
recho ${z##xyz}
expect '<abcdef>'
recho ${z%xyz}
expect '<abcdef>'
recho ${z%%xyz}
# Command substitution and the quirky differences between `` and $()
expect '<\$x>'
recho '\$x'
expect '<$x>'
recho `echo '\$x'`
expect '<\$x>'
recho $(echo '\$x')
# The difference between $* "$*" and "$@"
set "abc" "def ghi" "jkl"
expect '<abc> <def> <ghi> <jkl>'
recho $*
expect '<abc def ghi jkl>'
recho "$*"
OIFS="$IFS"
IFS=":$IFS"
# The special behavior of "$*", using the first character of $IFS as separator
expect '<abc:def ghi:jkl>'
recho "$*"
IFS="$OIFS"
expect '<abc> <def ghi> <jkl>'
recho "$@"
expect '<xxabc> <def ghi> <jklyy>'
recho "xx$@yy"
expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
recho "$@$@"
foo=abc
bar=def
expect '<abcdef>'
recho "$foo""$bar"
unset foo
set $foo bar '' xyz "$foo" abc
expect '<bar> <> <xyz> <> <abc>'
recho "$@"
# More tests of quoting and deferred evaluation
foo=10 x=foo
y='$'$x
expect '<$foo>'
recho $y
eval y='$'$x
expect '<10>'
recho $y
# case statements
NL='
'
x='ab
cd'
expect '<newline expected>'
case "$x" in
*$NL*) recho "newline expected" ;;
esac
expect '<got it>'
case \? in
*"?"*) recho "got it" ;;
esac
expect '<got it>'
case \? in
*\?*) recho "got it" ;;
esac
set one two three four five
expect '<one> <three> <five>'
recho $1 $3 ${5} $8 ${9}
# length tests on positional parameters and some special parameters
expect '<5> <5>'
recho $# ${#}
expect '<3>'
recho ${#1}
expect '<1>'
recho ${##}
expect '<1>'
recho ${#?}
expect '<5>'
recho ${#@}
expect '<5>'
recho ${#*}
expect '<5>'
recho "${#@}"
expect '<5>'
recho "${#*}"
expect '<42>'
recho $((28 + 14))
expect '<26>'
recho $[ 13 * 2 ]
expect '<\>'
recho `echo \\\\`
expect '<~>'
recho '~'
expect nothing
recho $!
expect nothing
recho ${!}
# test word splitting of assignment statements not preceding a command
a="a b c d e"
declare b=$a
expect '<a> <b> <c> <d> <e>'
recho $b
a="a?b?c"
echo ${a//\\?/ }
echo ${a//\?/ }
+21
View File
@@ -0,0 +1,21 @@
# Test the substitution quoting characters (CTLESC and CTLNUL) in different
# combinations
recho `echo ''`
recho `echo ""`
recho `echo `
# Test the unquoted special quoting characters
recho 
recho ""
recho ''
# This should give argv[1] = ^A argv[2] = ^?
FOO=`echo ' ' | tr ' ' '\012'`
recho $FOO
# Test patterns that come up when the shell quotes funny character
# combinations
recho ''
recho ''
recho ''
+94
View File
@@ -0,0 +1,94 @@
a=$'a\001b'
set $a
b=$a
c=$1
d="$1"
e=$'uv\001\001wx'
f=$'uv\001w\001xy'
set $e $e
recho ${e%%??}
recho "${e%%??}"
recho ${e%%???}
recho "${e%%???}"
recho ${a#?}
recho "${a#?}"
# simple variables
recho ${f##*$'\001'}
recho "${f##*$'\001'}"
recho ${f##*''} # literal ^A
recho "${f##*'^A'}" # two characters, `^' and `A'
recho ${e%$'\001'*}
recho "${e%$'\001'*}"
recho ${e#*$'\001'}
recho "${e#*$'\001'}"
# array members
arr[0]=$e
arr[1]=$f
recho ${arr[1]##*$'\001'}
recho "${arr[1]##*$'\001'}"
recho ${arr[1]##*''} # literal ^A
recho "${arr[1]##*'^A'}" # two characters, `^' and `A'
recho ${arr[0]%$'\001'*}
recho "${arr[0]%$'\001'*}"
recho ${arr[0]#*$'\001'}
recho "${arr[0]#*$'\001'}"
recho ${arr%$'\001'*}
recho "${arr%$'\001'*}"
recho ${arr#*$'\001'}
recho "${arr#*$'\001'}"
# positional parameters
set $e $f
recho ${2##*$'\001'}
recho "${2##*$'\001'}"
recho ${2##*''} # literal ^A
recho "${2##*''}" # literal ^A
recho ${2##*'^A'} # two characters, `^' and `A'
recho "${2##*'^A'}" # two characters, `^' and `A'
recho ${1%$'\001'*}
recho "${1%$'\001'*}"
recho ${1#*$'\001'}
recho "${1#*$'\001'}"
recho ${@%$'\001'*}
recho "${@%$'\001'*}"
recho ${@#*$'\001'}
recho "${@#*$'\001'}"
recho ${@##*''} # literal ^A
recho "${@##*'^A'}" # two characters, `^' and `A'
# arrays treated as a whole
recho ${arr[@]%$'\001'*}
recho "${arr[@]%$'\001'*}"
recho ${arr[@]#*$'\001'}
recho "${arr[@]#*$'\001'}"
recho ${arr[@]##*''} # literal ^A
recho "${arr[@]##*'^A'}" # two characters, `^' and `A'
# make sure command substitution works with CTLESC as well
a=$'ab\001cd\001ef'
recho $a
recho "$a"
recho $(echo $a)
recho $(echo "$a")
+86
View File
@@ -0,0 +1,86 @@
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <xxab>
argv[2] = <cd>
argv[3] = <efyy>
argv[1] = <ab^Acd^Aef>
argv[1] = <ab cd ef>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <ab>
argv[2] = <cd>
argv[1] = <ab^Acd^A>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <e>
argv[1] = <ab^Acd^Ae>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <>
argv[2] = <c>
argv[1] = <ab>
argv[2] = <-->
argv[3] = <cd>
argv[4] = <-->
argv[5] = <ef>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <ab>
argv[2] = <cd>
argv[3] = <ef>
argv[1] = <ab>
argv[2] = <-->
argv[3] = <cd>
argv[4] = <-->
argv[5] = <ef>
argv[1] = <uv^?wx^?yz>
argv[1] = <abyab^Acd^Aefz>
argv[1] = <abyab>
argv[2] = <cd>
argv[3] = <efz>
argv[1] = <abuv^?wx^?yzyab^Acd^Aefz>
argv[1] = <abuv^?wx^?yzyab>
argv[2] = <cd>
argv[3] = <efz>
argv[1] = <abuv^?wx^?yzyab>
argv[2] = <-->
argv[3] = <cd>
argv[4] = <-->
argv[5] = <efz>
argv[6] = <-->
argv[1] = <ab^Acd^Aef>
argv[1] = <uv>
argv[2] = <wx>
argv[3] = <yz>
argv[1] = <abyuv^?wx^?yzz>
argv[1] = <abyuv>
argv[2] = <wx>
argv[3] = <yzz>
argv[1] = <abuv^?wx^?yzyab^Acd^Aefz>
argv[1] = <abuv>
argv[2] = <wx>
argv[3] = <yzyab^Acd^Aefz>
argv[1] = <abuv^?wx^?yzyab>
argv[2] = <-->
argv[3] = <cd>
argv[4] = <-->
argv[5] = <efz>
argv[6] = <-->
argv[7] = <>
argv[1] = <abuv>
argv[2] = <-->
argv[3] = <wx>
argv[4] = <-->
argv[5] = <yzyab^Acd^Aefz>
argv[6] = <-->
argv[7] = <>
+63
View File
@@ -0,0 +1,63 @@
a=$'ab\001cd\001ef'
IFS=$'\001'
recho $a
recho ${a}
recho xx${a}yy
recho "$a"
recho $(echo $a)
recho $(echo "$a")
recho ${a%%??}
recho "${a%%??}"
recho ${a/f/}
recho "${a/f/}"
a1=("$a")
recho ${a1[0]}
recho ${a1}
recho ${a:2:2}
set -- $a
recho $1 -- $2 -- $3
set -- "$a"
recho $1
recho ${1}
echo "$a" | { IFS=$'\001' read x y z; recho $x -- $y -- $z ; }
unset x y z
b=$'uv\177wx\177yz'
recho $b
recho "ab${x}y${a}z"
recho ab${x}y${a}z
recho "ab${b}y${a}z"
recho ab${b}y${a}z
echo "ab${b}y${a}z" | { IFS=$'\001' read l m n o ; recho $l -- $m -- $n -- $o; }
unset l m n o
a=$'ab\001cd\001ef'
b=$'uv\177wx\177yz'
IFS=$'\177'
recho $a
recho $b
recho "ab${x}y${b}z"
recho ab${x}y${b}z
recho "ab${b}y${a}z"
recho ab${b}y${a}z
echo "ab${b}y${a}z" | { IFS=$'\001' read l m n o ; recho "$l" -- "$m" -- "$n" -- "$o"; }
unset l m n o
echo "ab${b}y${a}z" | { IFS=$'\177' read l m n o ; recho "$l" -- "$m" -- "$n" -- "$o"; }
unset l m n o
+43
View File
@@ -0,0 +1,43 @@
a=$'ab\001cd\001ef'
IFS=$'\001'
recho $a
recho ${a}
recho xx${a}yy
recho "$a"
recho $(echo $a)
recho $(echo "$a")
recho ${a%%??}
recho "${a%%??}"
recho ${a/f/}
recho "${a/f/}"
a1=("$a")
recho ${a1[0]}
recho ${a1}
recho ${a:2:2}
set -- $a
recho $1 -- $2 -- $3
set -- "$a"
recho $1
recho ${1}
echo "$a" | { IFS=$'\001' read x y z; recho $x -- $y -- $z ; }
unset x y z
b=$'uv\177wx\177yz'
recho $b
recho "ab${x}y${a}z"
recho ab${x}y${a}z
recho "ab${b}y${a}z"
recho ab${b}y${a}z
echo "ab${b}y${a}z" | { IFS=$'\001' read l m n o ; recho $l -- $m -- $n -- $o; }
+2 -1
View File
@@ -1,5 +1,6 @@
echo "warning: some of these tests may fail if process substitution has not" >&2
echo "warning: been compiled into the shell" >&2
echo "warning: been compiled into the shell or if the OS does not provide" >&2
echo "warning: /dev/fd." >&2
${THIS_SH} ./builtins.tests > /tmp/xx 2>&1
diff /tmp/xx builtins.right && rm -f /tmp/xx
+6
View File
@@ -0,0 +1,6 @@
echo "warning: some of these tests may fail if process substitution has not" >&2
echo "warning: been compiled into the shell or if the OS does not provide" >&2
ecoh "warning: /dev/fd." >&2
${THIS_SH} ./builtins.tests > /tmp/xx 2>&1
diff /tmp/xx builtins.right && rm -f /tmp/xx
+1 -1
View File
@@ -1,2 +1,2 @@
${THIS_SH} ./exp-tests | grep -v '^expect' > /tmp/xx
${THIS_SH} ./exp.tests | grep -v '^expect' > /tmp/xx
diff /tmp/xx exp.right && rm -f /tmp/xx
+2
View File
@@ -0,0 +1,2 @@
${THIS_SH} ./exp-tests | grep -v '^expect' > /tmp/xx
diff /tmp/xx exp.right && rm -f /tmp/xx
+2
View File
@@ -0,0 +1,2 @@
${THIS_SH} ./nquote5.tests 2>&1 | grep -v '^expect' > /tmp/xx
diff /tmp/xx nquote5.right && rm -f /tmp/xx
+4
View File
@@ -0,0 +1,4 @@
echo warning: some of these tests will fail if you do not have UTF-8 >&2
echo warning: locales installed on your system
${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > /tmp/xx
diff /tmp/xx nquote4.right && rm -f /tmp/xx