mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-12 06:30:50 +02:00
commit bash-20041027 snapshot
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
+18
-4
@@ -128,6 +128,10 @@ grep [ 123 ] *
|
||||
length = 3
|
||||
value = new1 new2 new3
|
||||
./array.tests: line 237: 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: syntax error near unexpected token `('
|
||||
./array2.sub: line 1: `declare -a ''=(a 'b c')'
|
||||
|
||||
a b c d e f g
|
||||
for case if then else
|
||||
@@ -135,10 +139,10 @@ for case if then else
|
||||
12 14 16 18 20
|
||||
4414758999202
|
||||
aaa bbb
|
||||
./array.tests: line 277: syntax error near unexpected token `<>'
|
||||
./array.tests: line 277: `metas=( <> < > ! )'
|
||||
./array.tests: line 278: syntax error near unexpected token `<>'
|
||||
./array.tests: line 278: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
|
||||
./array.tests: line 280: syntax error near unexpected token `<>'
|
||||
./array.tests: line 280: `metas=( <> < > ! )'
|
||||
./array.tests: line 281: syntax error near unexpected token `<>'
|
||||
./array.tests: line 281: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
|
||||
abc 3
|
||||
case 4
|
||||
abc case if then else 5
|
||||
@@ -178,3 +182,13 @@ negative offset 2 - expect seven
|
||||
seven
|
||||
out-of-range offset
|
||||
|
||||
e
|
||||
4
|
||||
1 4 7 10
|
||||
'b
|
||||
b c
|
||||
$0
|
||||
t
|
||||
[3]=abcde r s t u v
|
||||
e
|
||||
9
|
||||
|
||||
@@ -177,3 +177,14 @@ seven
|
||||
negative offset 2 - expect seven
|
||||
seven
|
||||
out-of-range offset
|
||||
|
||||
e
|
||||
4
|
||||
1 4 7 10
|
||||
'b
|
||||
b c
|
||||
$0
|
||||
t
|
||||
[3]=abcde r s t u v
|
||||
e
|
||||
9
|
||||
|
||||
@@ -236,6 +236,9 @@ echo "value = ${barray[*]}"
|
||||
set -u
|
||||
( echo ${#narray[4]} )
|
||||
|
||||
${THIS_SH} ./array1.sub
|
||||
${THIS_SH} ./array2.sub
|
||||
|
||||
# some old bugs and ksh93 compatibility tests
|
||||
set +u
|
||||
cd /tmp
|
||||
@@ -332,3 +335,62 @@ echo ${av[@]: -1:2}
|
||||
|
||||
echo out-of-range offset
|
||||
echo ${av[@]:12}
|
||||
|
||||
# parsing problems and other inconsistencies not fixed until post bash-3.0
|
||||
unset x
|
||||
declare -a x=(')' $$)
|
||||
[ ${x[1]} -eq $$ ] || echo bad
|
||||
|
||||
unset x
|
||||
declare -a x=(a b c d e)
|
||||
echo ${x[4]}
|
||||
|
||||
z=([1]=one [4]=four [7]=seven [10]=ten)
|
||||
|
||||
echo ${#z[@]}
|
||||
|
||||
echo ${!z[@]}
|
||||
|
||||
unset x
|
||||
declare -a x=(a \'b c\')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=(a 'b c')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=($0)
|
||||
[ "${x[@]}" = $0 ] || echo double expansion of \$0
|
||||
declare -a x=(\$0)
|
||||
echo "${x[@]}"
|
||||
|
||||
: ${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}
|
||||
|
||||
@@ -332,3 +332,65 @@ echo ${av[@]: -1:2}
|
||||
|
||||
echo out-of-range offset
|
||||
echo ${av[@]:12}
|
||||
|
||||
# parsing problems and other inconsistencies not fixed until post bash-3.0
|
||||
unset x
|
||||
declare -a x=(')' $$)
|
||||
[ ${x[1]} -eq $$ ] || echo bad
|
||||
|
||||
unset x
|
||||
declare -a x=(a b c d e)
|
||||
echo ${x[4]}
|
||||
|
||||
z=([1]=one [4]=four [7]=seven [10]=ten)
|
||||
|
||||
echo ${#z[@]}
|
||||
|
||||
echo ${!z[@]}
|
||||
|
||||
unset x
|
||||
declare -a x=(a \'b c\')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=(a 'b c')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=($0)
|
||||
[ "${x[@]}" = $0 ] || echo double expansion of \$0
|
||||
declare -a x=(\$0)
|
||||
echo "${x[@]}"
|
||||
|
||||
: ${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}
|
||||
|
||||
${THIS_SH} ./array1.sub
|
||||
${THIS_SH} ./array2.sub
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
printf "%s\n" -a a=(a 'b c')
|
||||
@@ -0,0 +1 @@
|
||||
declare -a ''=(a 'b c')
|
||||
@@ -51,3 +51,4 @@ this is ohio-state
|
||||
0
|
||||
1
|
||||
testb
|
||||
after
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
before exec1.sub: one two three
|
||||
calling exec1.sub
|
||||
aa bb cc dd ee
|
||||
after exec1.sub with args: 0
|
||||
|
||||
after exec1.sub without args: 0
|
||||
./execscript: line 20: notthere: command not found
|
||||
127
|
||||
/tmp/bash: notthere: No such file or directory
|
||||
127
|
||||
/bin/sh: /bin/sh: cannot execute binary file
|
||||
126
|
||||
./execscript: line 39: /: is a directory
|
||||
126
|
||||
/: /: cannot execute binary file
|
||||
126
|
||||
./execscript: line 46: .: /: is a directory
|
||||
1
|
||||
127
|
||||
0
|
||||
this is bashenv
|
||||
./exec3.sub: line 3: /tmp/bash-notthere: No such file or directory
|
||||
./exec3.sub: line 3: exec: /tmp/bash-notthere: cannot execute: No such file or directory
|
||||
126
|
||||
./execscript: line 68: notthere: No such file or directory
|
||||
127
|
||||
./execscript: line 71: notthere: No such file or directory
|
||||
127
|
||||
./execscript: line 74: notthere: No such file or directory
|
||||
127
|
||||
this is sh
|
||||
this is sh
|
||||
unset
|
||||
ok
|
||||
5
|
||||
./exec5.sub: line 4: exec: bash-notthere: not found
|
||||
127
|
||||
this is ohio-state
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
42
|
||||
42
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
testb
|
||||
@@ -104,3 +104,7 @@ ${THIS_SH} ./exec6.sub
|
||||
|
||||
# checks for properly deciding what constitutes an executable file
|
||||
${THIS_SH} ./exec7.sub
|
||||
|
||||
true | `echo true` &
|
||||
|
||||
echo after
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
if [ $UID -eq 0 ]; then
|
||||
echo "execscript: the test suite should not be run as root" >&2
|
||||
fi
|
||||
|
||||
set -- one two three
|
||||
echo before exec1.sub: "$@"
|
||||
echo calling exec1.sub
|
||||
./exec1.sub aa bb cc dd ee
|
||||
echo after exec1.sub with args: $?
|
||||
./exec1.sub
|
||||
echo after exec1.sub without args: $?
|
||||
|
||||
# set up a fixed path so we know notthere will not be found
|
||||
PATH=/usr/bin:/bin:/usr/local/bin:
|
||||
export PATH
|
||||
|
||||
notthere
|
||||
echo $?
|
||||
|
||||
# this is iffy, since the error messages may vary from system to system
|
||||
# and /tmp might not exist
|
||||
ln -s ${THIS_SH} /tmp/bash 2>/dev/null
|
||||
if [ -f /tmp/bash ]; then
|
||||
/tmp/bash notthere
|
||||
else
|
||||
${THIS_SH} notthere
|
||||
fi
|
||||
echo $?
|
||||
rm -f /tmp/bash
|
||||
|
||||
# /bin/sh should be there on all systems
|
||||
${THIS_SH} /bin/sh
|
||||
echo $?
|
||||
|
||||
# try executing a directory
|
||||
/
|
||||
echo $?
|
||||
|
||||
${THIS_SH} /
|
||||
echo $?
|
||||
|
||||
# try sourcing a directory
|
||||
. /
|
||||
echo $?
|
||||
|
||||
# try sourcing a binary file -- post-2.04 versions don't do the binary file
|
||||
# check, and will probably fail with `command not found', or status 127
|
||||
. ${THIS_SH} 2>/dev/null
|
||||
echo $?
|
||||
|
||||
# post-bash-2.05 versions allow sourcing non-regular files
|
||||
. /dev/null
|
||||
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
|
||||
${THIS_SH} ./exec3.sub
|
||||
rm -f /tmp/bashenv
|
||||
unset BASH_ENV
|
||||
|
||||
# we're resetting the $PATH to empty, so this should be last
|
||||
PATH=
|
||||
|
||||
notthere
|
||||
echo $?
|
||||
|
||||
command notthere
|
||||
echo $?
|
||||
|
||||
command -p notthere
|
||||
echo $?
|
||||
|
||||
# but -p should guarantee that we find all the standard utilities, even
|
||||
# with an empty or unset $PATH
|
||||
command -p sh -c 'echo this is $0'
|
||||
unset PATH
|
||||
command -p sh -c 'echo this is $0'
|
||||
|
||||
# a bug in bash before bash-2.01 caused PATH to be set to the empty string
|
||||
# when command -p was run with PATH unset
|
||||
echo ${PATH-unset}
|
||||
|
||||
echo "echo ok" | ${THIS_SH} -t
|
||||
|
||||
${THIS_SH} ./exec2.sub
|
||||
echo $?
|
||||
|
||||
${THIS_SH} ./exec4.sub
|
||||
|
||||
# try exec'ing a command that cannot be found in $PATH
|
||||
${THIS_SH} ./exec5.sub
|
||||
|
||||
# this was a bug in bash versions before bash-2.04
|
||||
${THIS_SH} -c 'cat </dev/null | cat >/dev/null' >&-
|
||||
|
||||
# checks for proper return values in subshell commands with inverted return
|
||||
# values
|
||||
|
||||
${THIS_SH} ./exec6.sub
|
||||
|
||||
# checks for properly deciding what constitutes an executable file
|
||||
${THIS_SH} ./exec7.sub
|
||||
@@ -372,3 +372,9 @@ 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//\?/ }
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
#
|
||||
# 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
|
||||
@@ -143,3 +143,5 @@ argv[2] = <b>
|
||||
argv[3] = <c>
|
||||
argv[4] = <d>
|
||||
argv[5] = <e>
|
||||
a?b?c
|
||||
a b c
|
||||
|
||||
@@ -24,3 +24,4 @@ match 15
|
||||
match 16
|
||||
match 17
|
||||
match 18
|
||||
ok 19
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
match 1
|
||||
match 2
|
||||
match 3
|
||||
match 4
|
||||
match 1a
|
||||
match 1b
|
||||
match 2a
|
||||
match 2b
|
||||
match 3a
|
||||
match 3b
|
||||
match 4a
|
||||
match 4b
|
||||
match 5
|
||||
match 6
|
||||
match 7
|
||||
match 8
|
||||
match 9
|
||||
match 10
|
||||
match 11
|
||||
match 12
|
||||
match 13
|
||||
match 14
|
||||
match 15
|
||||
match 16
|
||||
match 17
|
||||
match 18
|
||||
@@ -51,3 +51,6 @@ shopt -s extglob
|
||||
[[ ab/../ == +(??|a*)/..?(/) ]] && echo match 17
|
||||
|
||||
[[ ab/../ == +(a*)/..?(/) ]] && echo match 18
|
||||
|
||||
#
|
||||
j="@(x)" ; [[ x == $j ]] && echo ok 19
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
shopt -s extglob
|
||||
|
||||
[[ ab/../ == @(ab|+([^/]))/..?(/) ]] && echo match 1
|
||||
|
||||
[[ ab/../ == +([^/])/..?(/) ]] && echo match 2
|
||||
|
||||
[[ ab/../ == @(ab|?b)/..?(/) ]] && echo match 3
|
||||
|
||||
[[ ab/../ == +([^/])/../ ]] && echo match 4
|
||||
|
||||
[[ ab/../ == +([!/])/..?(/) ]] && echo match 1a
|
||||
|
||||
[[ ab/../ == @(ab|+([!/]))/..?(/) ]] && echo match 1b
|
||||
|
||||
[[ ab/../ == +([!/])/../ ]] && echo match 2a
|
||||
|
||||
[[ ab/../ == +([!/])/..?(/) ]] && echo match 2b
|
||||
|
||||
[[ ab/../ == +([!/])/..@(/) ]] && echo match 3a
|
||||
|
||||
[[ ab/../ == +(ab)/..?(/) ]] && echo match 3b
|
||||
|
||||
[[ ab/../ == [!/][!/]/../ ]] && echo match 4a
|
||||
|
||||
[[ ab/../ == @(ab|?b)/..?(/) ]] && echo match 4b
|
||||
|
||||
[[ ab/../ == [^/][^/]/../ ]] && echo match 5
|
||||
|
||||
[[ ab/../ == ?b/..?(/) ]] && echo match 6
|
||||
|
||||
[[ ab/../ == +(?b)/..?(/) ]] && echo match 7
|
||||
|
||||
[[ ab/../ == +(?b|?b)/..?(/) ]] && echo match 8
|
||||
|
||||
[[ ab/../ == @(?b|?b)/..?(/) ]] && echo match 9
|
||||
|
||||
[[ ab/../ == @(a?|?b)/..?(/) ]] && echo match 10
|
||||
|
||||
[[ ab/../ == ?(ab)/..?(/) ]] && echo match 11
|
||||
|
||||
[[ ab/../ == ?(ab|??)/..?(/) ]] && echo match 12
|
||||
|
||||
[[ ab/../ == @(??)/..?(/) ]] && echo match 13
|
||||
|
||||
[[ ab/../ == @(??|a*)/..?(/) ]] && echo match 14
|
||||
|
||||
[[ ab/../ == @(a*)/..?(/) ]] && echo match 15
|
||||
|
||||
[[ ab/../ == +(??)/..?(/) ]] && echo match 16
|
||||
|
||||
[[ ab/../ == +(??|a*)/..?(/) ]] && echo match 17
|
||||
|
||||
[[ ab/../ == +(a*)/..?(/) ]] && echo match 18
|
||||
@@ -0,0 +1,10 @@
|
||||
é
|
||||
1
|
||||
AéB
|
||||
B
|
||||
B
|
||||
ok 1
|
||||
ok 2
|
||||
aéb
|
||||
0000000 141 303 251 142
|
||||
0000004
|
||||
@@ -0,0 +1,38 @@
|
||||
LANG=en_US.UTF-8
|
||||
|
||||
a=$'\303\251'
|
||||
|
||||
echo "$a"
|
||||
|
||||
echo ${#a}
|
||||
|
||||
b=$'A\303\251B'
|
||||
|
||||
echo "$b"
|
||||
|
||||
echo ${b: -1}
|
||||
|
||||
c=AeB
|
||||
|
||||
echo ${c: -1}
|
||||
|
||||
unset a
|
||||
a=$(printf '%b' 'A\303\251B')
|
||||
IFS=$(printf '%b' '\303\251')
|
||||
|
||||
case "$a" in
|
||||
"A${IFS}B") echo ok 1 ;;
|
||||
*) echo bad 1 ;;
|
||||
esac
|
||||
|
||||
set $a
|
||||
|
||||
case $1 in
|
||||
A) echo ok 2 ;;
|
||||
*) echo bad 2 ;;
|
||||
esac
|
||||
|
||||
set a b
|
||||
|
||||
printf '%s\n' "$*"
|
||||
printf '%s' "$*" | od -b
|
||||
@@ -0,0 +1,38 @@
|
||||
LANG=en_US.UTF-8
|
||||
|
||||
a=$'\303\251'
|
||||
|
||||
echo "$a"
|
||||
|
||||
echo ${#a}
|
||||
|
||||
b=$'A\303\251B'
|
||||
|
||||
echo "$b"
|
||||
|
||||
echo ${b: -1}
|
||||
|
||||
c=AeB
|
||||
|
||||
echo ${c: -1}
|
||||
|
||||
unset a
|
||||
a=$(printf '%b' 'A\303\251B')
|
||||
IFS=$(printf '%b' '\303\251')
|
||||
|
||||
case "$a" in
|
||||
"A${IFS}B") echo yes ;;
|
||||
*) echo no ;;
|
||||
esac
|
||||
|
||||
set $a
|
||||
|
||||
case $1 in
|
||||
A) echo ok 2 ;;
|
||||
*) echo bad 2 ;;
|
||||
esac
|
||||
|
||||
set a b
|
||||
|
||||
printf '%s\n' "$*"
|
||||
printf '%s' "$*" | od -b
|
||||
@@ -94,3 +94,5 @@ after read
|
||||
0
|
||||
0
|
||||
0
|
||||
before block
|
||||
after block
|
||||
|
||||
@@ -156,3 +156,18 @@ ${THIS_SH} ./redir5.sub
|
||||
|
||||
# test behavior after a write error with a builtin command
|
||||
${THIS_SH} ./redir6.sub
|
||||
|
||||
# problem with redirections using fds bash uses internally
|
||||
: ${TMPDIR:=/tmp}
|
||||
|
||||
trap 'rm -f $TMPDIR/bash-redir-$$' 0 1 2 3 6 15
|
||||
|
||||
echo before block
|
||||
{
|
||||
echo before redir
|
||||
exec 10>&1
|
||||
echo after redir
|
||||
} > $TMPDIR/bash-redir-$$
|
||||
|
||||
echo after block
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
# catch-all for remaining untested redirection stuff
|
||||
set +o posix
|
||||
|
||||
echo abc > /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
set -o noclobber
|
||||
|
||||
#this should be an error
|
||||
echo def > /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
# but this should succeed
|
||||
echo def > /tmp/redir-test-2
|
||||
cat /tmp/redir-test-2
|
||||
|
||||
# and so should this
|
||||
echo def >| /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
set +o noclobber
|
||||
rm /tmp/redir-test /tmp/redir-test-2
|
||||
|
||||
# this should be an error
|
||||
z="a b"
|
||||
cat < $z
|
||||
|
||||
echo "Point 1"
|
||||
|
||||
exec 3</etc/passwd
|
||||
exec 4>/tmp/bash-a
|
||||
exec 5>/tmp/bash-b
|
||||
echo "Point 2"
|
||||
|
||||
echo to a 1>&4
|
||||
echo to b 1>&5
|
||||
cat /tmp/bash-a
|
||||
cat /tmp/bash-b
|
||||
exec 11</dev/null
|
||||
echo "Point 3"
|
||||
|
||||
echo to a 1>&4
|
||||
echo to b 1>&5
|
||||
cat /tmp/bash-a
|
||||
cat /tmp/bash-b
|
||||
|
||||
exec 11<&-
|
||||
echo "Point 4"
|
||||
|
||||
exec 6<>/tmp/bash-c
|
||||
echo to c 1>&6
|
||||
cat /tmp/bash-c
|
||||
echo "Point 5"
|
||||
|
||||
rm -f /tmp/bash-a /tmp/bash-b /tmp/bash-c
|
||||
|
||||
#
|
||||
# Test the effect of input buffering on the shell's input
|
||||
#
|
||||
${THIS_SH} < redir1.sub
|
||||
|
||||
# more open, close, duplicate file descriptors
|
||||
${THIS_SH} ./redir3.sub < ./redir3.in1
|
||||
|
||||
# still more redirections
|
||||
${THIS_SH} ./redir4.sub < redir4.in1
|
||||
|
||||
# various forms of null redirection
|
||||
testf()
|
||||
{
|
||||
if [ -f "$1" ]; then
|
||||
rm -f "$1"
|
||||
else
|
||||
echo oops -- $1 not found
|
||||
fi
|
||||
}
|
||||
|
||||
> /tmp/null-redir-a
|
||||
testf /tmp/null-redir-a
|
||||
|
||||
$EXIT > /tmp/null-redir-b
|
||||
testf /tmp/null-redir-b
|
||||
|
||||
( > /tmp/null-redir-c )
|
||||
testf /tmp/null-redir-c
|
||||
|
||||
$EXIT > /tmp/null-redir-d &
|
||||
wait
|
||||
testf /tmp/null-redir-d
|
||||
|
||||
exit 3 | $EXIT > /tmp/null-redir-e
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
testf /tmp/null-redir-e
|
||||
|
||||
exit 4 | > /tmp/null-redir-f
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
testf /tmp/null-redir-f
|
||||
|
||||
> /tmp/null-redir-g &
|
||||
wait
|
||||
testf /tmp/null-redir-g
|
||||
|
||||
exec >/tmp/null-redir-h &
|
||||
wait
|
||||
testf /tmp/null-redir-h
|
||||
|
||||
# make sure async commands don't get /dev/null as stdin when an explicit
|
||||
# input redirection is supplied
|
||||
for x in 1 2 3; do
|
||||
{ read line ; echo $line ; } &
|
||||
wait
|
||||
{ read line ; echo $line ; } &
|
||||
wait
|
||||
done << EOF
|
||||
ab
|
||||
cd
|
||||
ef
|
||||
gh
|
||||
ij
|
||||
kl
|
||||
EOF
|
||||
|
||||
# make sure async commands get /dev/null as stdin in the absence of any
|
||||
# input redirection
|
||||
/bin/cat &
|
||||
wait
|
||||
echo $?
|
||||
|
||||
# make sure that loops work OK with here documents and are not run in
|
||||
# subshells
|
||||
while read line; do
|
||||
echo $line
|
||||
l2=$line
|
||||
done << EOF
|
||||
ab
|
||||
cd
|
||||
EOF
|
||||
echo $l2
|
||||
|
||||
# These should not echo anything -- bug in versions before 2.04
|
||||
( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1
|
||||
|
||||
( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 | cat
|
||||
|
||||
# in posix mode, non-interactive shells are not allowed to perform
|
||||
# filename expansion on input redirections, even if they expand to
|
||||
# a single filename
|
||||
set -o posix
|
||||
cat < redir1.*
|
||||
|
||||
# test ksh93 dup-and-close (move fd) redirections
|
||||
${THIS_SH} ./redir5.sub
|
||||
|
||||
# test behavior after a write error with a builtin command
|
||||
${THIS_SH} ./redir6.sub
|
||||
@@ -0,0 +1,7 @@
|
||||
# See whether or not we can use `diff -a'
|
||||
( diff -a ./intl.right ./intl.right >/dev/null 2>&1 ) && AFLAG=-a
|
||||
|
||||
echo "warning: some of these tests will fail if you do not have UTF-8" >&2
|
||||
echo "warning: locales installed on your system." >&2
|
||||
${THIS_SH} ./intl.tests > /tmp/xx
|
||||
diff $AFLAG /tmp/xx intl.right && rm -f /tmp/xx
|
||||
@@ -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." >&2
|
||||
${THIS_SH} ./intl.tests > /tmp/xx
|
||||
diff /tmp/xx intl.right && rm -f /tmp/xx
|
||||
@@ -15,3 +15,10 @@ ok
|
||||
~
|
||||
make -k FOO=/usr/xyz/mumble
|
||||
/usr/xyz/mumble
|
||||
HOME=~
|
||||
HOME=~
|
||||
/usr/$x/abc
|
||||
HOME=~
|
||||
/usr/$x/abc
|
||||
HOME=/usr/$x/abc
|
||||
/usr/$x/abc
|
||||
|
||||
@@ -44,3 +44,27 @@ echo make -k FOO=~/mumble
|
||||
|
||||
typeset FOO=~/mumble
|
||||
echo "$FOO"
|
||||
|
||||
h=HOME=~
|
||||
echo $h
|
||||
|
||||
export h=HOME=~
|
||||
echo $h
|
||||
|
||||
x=1234
|
||||
HOME='/usr/$x/abc'
|
||||
|
||||
echo ~
|
||||
|
||||
# behavior differs here in posix mode
|
||||
set -o posix
|
||||
|
||||
eval echo $h
|
||||
eval $h
|
||||
echo $HOME
|
||||
|
||||
set +o posix
|
||||
|
||||
eval echo $h
|
||||
eval $h
|
||||
echo $HOME
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
HOME=/usr/xyz
|
||||
XPATH=/bin:/usr/bin:.
|
||||
|
||||
ADDPATH=PATH=~/bin:$XPATH
|
||||
|
||||
echo $ADDPATH
|
||||
|
||||
unset ADDPATH
|
||||
: ${ADDPATH:=~/bin:~/bin2:$XPATH}
|
||||
echo $ADDPATH
|
||||
|
||||
unset ADDPATH
|
||||
: ${ADDPATH:=PATH=~/bin:~/bin2:$XPATH}
|
||||
echo $ADDPATH
|
||||
|
||||
cat << !
|
||||
~/bin
|
||||
!
|
||||
|
||||
echo "~"
|
||||
|
||||
echo ${TPATH:-~}
|
||||
echo "${TPATH:-~}"
|
||||
echo "${TPATH:-"~"}"
|
||||
|
||||
echo "${XPATH+~}"
|
||||
|
||||
recho "\a"
|
||||
recho "${TPATH:-\a}"
|
||||
|
||||
SHELL=~/bash
|
||||
echo $SHELL
|
||||
|
||||
case $SHELL in
|
||||
~/bash) echo ok;;
|
||||
*) echo bad;;
|
||||
esac
|
||||
|
||||
somevar=
|
||||
echo "${somevar:-~}"
|
||||
echo "${somevar:-"~"}"
|
||||
|
||||
echo make -k FOO=~/mumble
|
||||
|
||||
typeset FOO=~/mumble
|
||||
echo "$FOO"
|
||||
|
||||
h=HOME=~
|
||||
echo $h
|
||||
|
||||
export h=HOME=~
|
||||
echo $h
|
||||
|
||||
x=1234
|
||||
HOME='/usr/$x/abc'
|
||||
|
||||
echo ~
|
||||
|
||||
eval echo $h
|
||||
eval $h
|
||||
|
||||
echo $HOME
|
||||
Reference in New Issue
Block a user