Imported from ../bash-2.05.tar.gz.

This commit is contained in:
Jari Aalto 2001-04-06 19:14:31 +00:00
commit 28ef6c316f
251 changed files with 22319 additions and 12413 deletions

View file

@ -70,3 +70,5 @@ fx ()
./arith-for.tests: line 83: syntax error: `;' unexpected
./arith-for.tests: line 83: syntax error: `(( i=0; i < 3; i++; 7 ))'
2
20
20

View file

@ -85,3 +85,10 @@ do
echo $i
done
echo $?
# one-liners added in post-bash-2.04
for ((i=0; i < 20; i++)) do : ; done
echo $i
for ((i=0; i < 20; i++)) { : ; }
echo $i

View file

@ -144,3 +144,9 @@ ok
./arith.tests: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
./arith.tests: a b: syntax error in expression (error token is "b")
./arith.tests: ((: a b: syntax error in expression (error token is "b")
42
42
42
42
42
42

View file

@ -267,3 +267,11 @@ echo $x $y
# These are errors
echo $((a b))
((a b))
n=42
printf "%d\n" $n
printf "%i\n" $n
echo $(( 8#$(printf "%o\n" $n) ))
printf "%u\n" $n
echo $(( 16#$(printf "%x\n" $n) ))
echo $(( 16#$(printf "%X\n" $n) ))

View file

@ -110,11 +110,20 @@ for case if then else
<> < > !
12 14 16 18 20
4414758999202
./array.tests: array assign: line 257: syntax error near unexpected token `for'
./array.tests: array assign: line 257: `a b c for case if then else'
./array.tests: array assign: line 259: syntax error near unexpected token `for'
./array.tests: array assign: line 259: `for case if then else'
./array.tests: array assign: line 261: syntax error near unexpected token `<>'
./array.tests: array assign: line 261: ` <> < > ! '
./array.tests: array assign: line 262: syntax error near unexpected token `[1]=<>'
./array.tests: array assign: line 262: ` [1]=<> [2]=< [3]=> [4]=! '
aaa bbb
./array.tests: array assign: line 262: syntax error near unexpected token `for'
./array.tests: array assign: line 262: `a b c for case if then else'
./array.tests: array assign: line 264: syntax error near unexpected token `for'
./array.tests: array assign: line 264: `for case if then else'
./array.tests: array assign: line 266: syntax error near unexpected token `<>'
./array.tests: array assign: line 266: ` <> < > ! '
./array.tests: array assign: line 267: syntax error near unexpected token `[1]=<>'
./array.tests: array assign: line 267: ` [1]=<> [2]=< [3]=> [4]=! '
abc 3
0
abc 1
abc 1
0
0
1
1

View file

@ -253,6 +253,11 @@ echo ${foo[@]}
foo=( 4414758999202 )
echo ${foo[@]}
# this was a bug in all versions of bash 2.x up to and including bash-2.04
declare -a ddd=(aaa
bbb)
echo ${ddd[@]}
# errors
foo=(a b c for case if then else)
@ -260,3 +265,16 @@ foo=(for case if then else)
metas=( <> < > ! )
metas=( [1]=<> [2]=< [3]=> [4]=! )
# various expansions that didn't really work right until post-bash-2.04
foo='abc'
echo ${foo[0]} ${#foo[0]}
echo ${foo[1]} ${#foo[1]}
echo ${foo[@]} ${#foo[@]}
echo ${foo[*]} ${#foo[*]}
foo=''
echo ${foo[0]} ${#foo[0]}
echo ${foo[1]} ${#foo[1]}
echo ${foo[@]} ${#foo[@]}
echo ${foo[*]} ${#foo[*]}

View file

@ -2,6 +2,10 @@ returns: 0
returns: 0
returns: 1
returns: 0
returns: 0
returns: 0
returns: 0
returns: 0
returns: 1
returns: 0
returns: 0

View file

@ -20,6 +20,19 @@ echo returns: $?
[[ ! x || x ]]
echo returns: $?
# parenthesized terms didn't work right until post-2.04
[[ a ]]
echo returns: $?
[[ (a) ]]
echo returns: $?
[[ -n a ]]
echo returns: $?
[[ (-n a) ]]
echo returns: $?
# unset variables don't need to be quoted
[[ -n $UNSET ]]
echo returns: $?

View file

@ -55,8 +55,8 @@ tf2 ()
{
( {
time -p echo a | cat - >/dev/null
} )
} 2>&1
} ) 2>&1
}
cprint.tests is a regular file
cprint.tests is not a directory
a

View file

@ -117,3 +117,94 @@ unset IFS
recho "$@"
recho $@
recho "$*"
IFS=:
# special variables
set -- 1 2 3 4 5 6 7 8 9 10
bar=${*}
foo=$*
echo foo = "$foo"
echo bar = "$bar"
foo1=$@
bar1=${@}
echo foo1 = "$foo1"
echo bar1 = "$bar1"
foo2="$*"
bar2="${*}"
echo foo2 = "$foo2"
echo bar2 = "$bar2"
eval foo3='$*' bar3='${*}'
echo foo3 = "$foo3"
echo bar3 = "$bar3"
case $* in
*\:*) echo ok 1;;
*) echo bad 1;;
esac
case $@ in
*\:*) echo bad 2;;
*) echo ok 2;;
esac
case "$*" in
*\:*) echo ok 3;;
*) echo bad 3;;
esac
case "$@" in
*\:*) echo bad 4;;
*) echo ok 4;;
esac
IFS=$' \t\n'
bar=${*}
foo=$*
echo foo = "$foo"
echo bar = "$bar"
foo1=$@
bar1=${@}
echo foo1 = "$foo1"
echo bar1 = "$bar1"
foo2="$*"
bar2="${*}"
echo foo2 = "$foo2"
echo bar2 = "$bar2"
eval foo3='$*' bar3='${*}'
echo foo3 = "$foo3"
echo bar3 = "$bar3"
case $* in
*\ *) echo ok 1;;
*) echo bad 1;;
esac
case $@ in
*\ *) echo ok 2;;
*) echo bad 2;;
esac
case "$*" in
*\ *) echo ok 3;;
*) echo bad 3;;
esac
case "$@" in
*\ *) echo ok 4;;
*) echo bad 4;;
esac
exit 0

View file

@ -71,3 +71,27 @@ argv[1] = <foo>
argv[2] = <bar>
argv[3] = <bam>
argv[1] = <foo bar bam>
foo = 1:2:3:4:5:6:7:8:9:10
bar = 1:2:3:4:5:6:7:8:9:10
foo1 = 1 2 3 4 5 6 7 8 9 10
bar1 = 1 2 3 4 5 6 7 8 9 10
foo2 = 1:2:3:4:5:6:7:8:9:10
bar2 = 1:2:3:4:5:6:7:8:9:10
foo3 = 1:2:3:4:5:6:7:8:9:10
bar3 = 1:2:3:4:5:6:7:8:9:10
ok 1
ok 2
ok 3
ok 4
foo = 1 2 3 4 5 6 7 8 9 10
bar = 1 2 3 4 5 6 7 8 9 10
foo1 = 1 2 3 4 5 6 7 8 9 10
bar1 = 1 2 3 4 5 6 7 8 9 10
foo2 = 1 2 3 4 5 6 7 8 9 10
bar2 = 1 2 3 4 5 6 7 8 9 10
foo3 = 1 2 3 4 5 6 7 8 9 10
bar3 = 1 2 3 4 5 6 7 8 9 10
ok 1
ok 2
ok 3
ok 4

View file

@ -16,7 +16,7 @@ notthere: notthere: No such file or directory
126
./execscript: .: /: is a directory
1
126
127
./execscript: .: /dev/null: not a regular file
1
this is bashenv
@ -37,3 +37,17 @@ ok
./exec5.sub: exec: bash-notthere: not found
127
this is ohio-state
0
1
1
0
42
42
0
1
1
0
0
1
0
1

54
tests/exec6.sub Normal file
View file

@ -0,0 +1,54 @@
# builtins with exit status inverted
( true )
echo $?
( ! true )
echo $?
( false )
echo $?
( ! false )
echo $?
# inverting shouldn't affect exit
(exit 42)
echo $?
( ! exit 42 )
echo $?
# commands requiring an exec with exit status inverted -- broken in bash-2.04
( ls > /dev/null 2>&1 )
echo $?
( ! ls > /dev/null 2>&1 )
echo $?
touch /tmp/notwrite
chmod 400 /tmp/notwrite
# make sure redirection failures in commands whose exit status is inverted
# are handled correctly
( ls > /tmp/notwrite ) 2>/dev/null
echo $?
( ! ls > /tmp/notwrite ) 2>/dev/null
echo $?
# now add exit traps, true and false for commands with and without exit
# status inversion
(trap 'false' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null
echo $?
(trap 'false' 0 ; ls > /tmp/notwrite ) 2>/dev/null
echo $?
(trap 'true' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null
echo $?
(trap 'true' 0 ; ls > /tmp/notwrite ) 2>/dev/null
echo $?
rm -f /tmp/notwrite

View file

@ -35,6 +35,8 @@ echo $?
. /
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 $?
@ -82,3 +84,8 @@ ${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

View file

@ -118,3 +118,33 @@ testgrp ()
} 1>&2;
echo testgrp-b
}
funca is a function
funca ()
{
( echo func-a )
}
funcb is a function
funcb ()
{
( echo func-b )
}
funcc is a function
funcc ()
{
( echo func-c ) 2>&1
}
func-a
func-b
func-c
expect 5 10
5 10
expect 20
20
expect 5 20
5 20
expect 5 30
5 30
expect 2 40
2 40
expect 5 20
5 20

View file

@ -150,4 +150,11 @@ ${THIS_SH} -c 'type zf'
${THIS_SH} ./func1.sub
# tests for functions whose bodies are not group commands, with and without
# attached redirections
${THIS_SH} ./func2.sub
# test for some posix-specific function behavior
${THIS_SH} ./func3.sub
exit 0

17
tests/func2.sub Normal file
View file

@ -0,0 +1,17 @@
funca() (
echo func-a
)
funcb() ( echo func-b )
funcc() (
echo func-c
) 2>&1
type funca
type funcb
type funcc
funca
funcb
funcc

54
tests/func3.sub Normal file
View file

@ -0,0 +1,54 @@
#
# test some posix-mode-specific function behavior
#
set -o posix
func()
{
return 5
}
myfunction () {
var=20 return
}
var=10
echo expect 5 10
func
echo $? $var
myfunction
echo expect 20
echo $var
echo expect 5 20
func
echo $? $var
echo expect 5 30
var=30 func
echo $? $var
: ${TMPDIR:=/tmp}
TMPFILE=$TMPDIR/func3.sub.$$
rm -f $TMPFILE
echo 'var=40 return 2' > $TMPFILE
# test the behavior of `return' and preceding variable assignments here
# because it's convenient
var=10
echo expect 2 40
. $TMPFILE
echo $? $var
rm -f $TMPFILE
#set -o posix
var=0
func()
{
var=20 return 5
}
echo expect 5 20
var=30 func
echo $? $var

View file

@ -296,6 +296,11 @@ case p in
[a-\z]) echo ok 36 ;;
esac
# this was a bug in all versions up to bash-2.04-release
case "/tmp" in
[/\\]*) echo ok 37 ;;
esac
# none of these should output anything
case abc in

View file

@ -94,6 +94,7 @@ ok 33
ok 34
ok 35
ok 36
ok 37
argv[1] = <b>
argv[2] = <bb>
argv[3] = <bcd>

View file

@ -206,3 +206,9 @@ argv[1] = <xxx>
argv[2] = <yyy>
1
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <:a:>
argv[1] = <:b:>
argv[1] = <>
argv[1] = <>

View file

@ -481,4 +481,21 @@ set -- ''
expect 1
echo $#
expect '<>'
recho "${@}"
expect '<>'
recho "${@-}"
expect '<>'
recho "${@:-}"
# this was a bug in bash-2.04, fixed in 2.05
set -- a b
expect '<:a:>' '<:b:>'
for i in "${@-}"; do recho :$i:; done
# I believe that ksh93 does these wrong -- we're using the rhs, so shouldn't
# it behave the same as ""?
set --
expect '<>'
recho "${@-}"
expect '<>'
recho "${@:-}"

View file

@ -48,6 +48,12 @@ argv[2] = <ef>
argv[3] = <gh ij>
argv[4] = <kl mn>
argv[5] = <op>
argv[1] = </home/chet/foo//bar/abcabcabc>
argv[1] = <home/chet/foo//bar/abcabcabc>
argv[1] = <home>
argv[1] = <home>
argv[1] = <home>
argv[1] = <home>
argv[1] = <abcdefghijklmnop>
argv[1] = <4>
argv[1] = <op>

View file

@ -118,6 +118,32 @@ recho "${@:3:4}"
expect '<ab cd> <ef> <gh ij> <kl mn> <op>'
recho "${@:1:$#}"
# code to ad-hoc parse arithmetic expressions in substring expansions was
# broken until post-2.04
base=/home/chet/foo//bar
string1=$base/abcabcabc
x=1 j=4
expect '</home/chet/foo//bar/abcabcabc>'
recho ${string1:0}
expect '<home/chet/foo//bar/abcabcabc>'
recho ${string1:1}
expect '<home>'
recho ${string1:(j?1:0):j}
expect '<home>'
recho ${string1:j?1:0:j}
expect '<home>'
recho ${string1:(j?(x?1:0):0):j}
expect '<home>'
recho ${string1:j?(x?1:0):0:j}
unset base string1 x j
# indirect variable references
expect '<abcdefghijklmnop>'
recho ${!9:-$z}

View file

@ -140,18 +140,20 @@ if [ "$OPTIND" != 3 ] || [ "$store" != a ] || [ "$OPTARG" != aoptval ]; then
testfail "getopts"
fi
# if I change the default quoting style for variable values, these
# next four must change
newtest
SQUOTE="'"
val1=$(set | sed -n 's:^SQUOTE=::p')
# if I change the default quoting style for variable values, this must change
if [ "$val1" != "''\'''" ]; then
if [ "$val1" != "\$'\\''" ]; then
testfail "variable quoting 1"
fi
newtest
VTILDE='~'
val1=$(set | sed -n 's:^VTILDE=::p')
if [ "$val1" != "'~'" ]; then
if [ "$val1" != "\$'~'" ]; then
testfail "variable quoting 2"
fi
@ -165,7 +167,7 @@ fi
newtest
VHASH2=#abcd
val1=$(set | sed -n 's:^VHASH2=::p')
if [ "$val1" != "'#abcd'" ]; then
if [ "$val1" != "\$'#abcd'" ]; then
testfail "variable quoting 4"
fi

View file

@ -14,6 +14,21 @@ if : ; then
done
set +e
fi
(
set -e
false
echo bad
)
echo $?
x=$(
set -e
false
echo bad
)
echo $? $x
# command subst should not inherit -e
set -e
echo $(false; echo ok)

View file

@ -13,6 +13,8 @@
7
8
9
1
1
ok
hi
while succeeded

View file

@ -98,7 +98,7 @@ set +o verbose
set +o xtrace
set -o history
set +o ignoreeof
set +o interactive-comments
set -o interactive-comments
set +o posix
set -o emacs
set +o vi
@ -122,7 +122,7 @@ verbose off
xtrace off
history on
ignoreeof off
interactive-comments off
interactive-comments on
posix off
emacs on
vi off
@ -146,7 +146,7 @@ set +o verbose
set +o xtrace
set -o history
set +o ignoreeof
set +o interactive-comments
set -o interactive-comments
set +o posix
set -o emacs
set +o vi
@ -160,6 +160,7 @@ set -o histexpand
set -o monitor
set -o privileged
set -o history
set -o interactive-comments
set -o emacs
--
set +o allexport
@ -175,7 +176,6 @@ set +o physical
set +o verbose
set +o xtrace
set +o ignoreeof
set +o interactive-comments
set +o posix
set +o vi
--
@ -192,7 +192,6 @@ physical off
verbose off
xtrace off
ignoreeof off
interactive-comments off
posix off
vi off
--

View file

@ -270,3 +270,15 @@ b ( 1 = 2
2
./test.tests: test: (: unary operator expected
2
t -t a
1
t -t addsds
1
t -t 42
1
t -t /dev/tty
1
t -t /dev/tty4
1
t -t /dev/tty4444444...
1

View file

@ -407,3 +407,17 @@ t 4 -eq 4 -a 3 4
echo $?
t \( \)
# non-numeric arguments to `test -t' should return failure -- fix in 2.05
echo 't -t a'
t -t a
echo 't -t addsds'
t -t addsds
echo 't -t 42'
t -t 42
echo 't -t /dev/tty'
t -t /dev/tty
echo 't -t /dev/tty4'
t -t /dev/tty4
echo 't -t /dev/tty4444444...'
t -t /dev/tty4444444...

View file

@ -44,6 +44,7 @@ trap -- '' SIGINT
trap -- 'echo aborting' SIGQUIT
trap -- 'echo aborting' SIGABRT
trap -- 'echo aborting' SIGTERM
0
caught a child death
caught a child death
caught a child death

View file

@ -40,6 +40,15 @@ trap '' int
trap
# exit 0 in exit trap should set exit status
(
set -e
trap 'exit 0' EXIT
false
echo bad
)
echo $?
# hmmm...should this set the handling to SIG_IGN for children, too?
trap '' USR2
./trap1.sub

View file

@ -29,8 +29,12 @@ declare -i ivar="10"
unset
declare -x ivar="42"
hB
braceexpand:hashall
braceexpand:hashall:interactive-comments
hPB
braceexpand:hashall:physical
declare -r SHELLOPTS="braceexpand:hashall:physical"
braceexpand:hashall:physical:interactive-comments
declare -r SHELLOPTS="braceexpand:hashall:physical:interactive-comments"
abcde
20
30
40
50

View file

@ -194,3 +194,7 @@ set -a
typeset FOOFOO=abcde
printenv FOOFOO
# test out export behavior of variable assignments preceding builtins and
# functions
$THIS_SH ./varenv1.sub

28
tests/varenv1.sub Normal file
View file

@ -0,0 +1,28 @@
# test out the export behavior of variable assignments preceding `eval', `.'
# and shell functions
func()
{
printenv var
}
export var=10
echo expect 20
var=20 eval printenv var
: ${TMPDIR:=/tmp}
TMPFILE=$TMPDIR/evalsub.$$
rm -f $TMPFILE
echo 'printenv var' > $TMPFILE
echo expect 30
var=30 . $TMPFILE
rm -f $TMPFILE
echo expect 40
var=40 func
echo expect 50
var=50 command printenv var