builtins.sh revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2007 AT&T Knowledge Ventures #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Knowledge Ventures #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
# test shell builtin commands
integer Errors=0
builtin getconf
set -- - foobar
set -- -x foobar
OPTIND=1
getopts :r:s var -r
then err_exit "'getopts :r:s var -r' not working"
fi
OPTIND=1
getopts :d#u var -d 100
fi
OPTIND=1
while getopts 'ab' option -a -b
done
USAGE=$'[-][S:server?Operate on the specified \asubservice\a:]:[subservice:=pmserver]
{
[p:pmserver]
[r:repserver]
[11:notifyd]
}'
while (( $# > 1 ))
do OPTIND=1
shift 2
done
read <<!
!
print x:y | IFS=: read a b
if [[ $a != x ]]
then err_exit "IFS=: read ... not working"
fi
read <<!
hello \
!
read -d x <<!
!
read <<\!
hello \
world \
!
print "one\ntwo" | { read line
read line
}
read <<\!
\
a\
\
\
b
!
then err_exit "read multiple continuation failed"
fi
then err_exit "read from pipeline failed"
fi
if [[ $line != "" ]]
fi
if [[ $(print -R -) != - ]]
then err_exit "print -R not working correctly"
fi
if [[ $(print -- -) != - ]]
then err_exit "print -- not working correctly"
fi
then err_exit "%n format of printf not working"
fi
x=$0
if [[ $(eval 'print $0') != $x ]]
then err_exit '$0 not correct for eval'
fi
unset x
readonly x
set -- $(readonly)
if [[ " $@ " != *" x "* ]]
then err_exit 'unset readonly variables are not displayed'
fi
do print $i
continue 10
done
) != $'foo\nbar' ]]
then err_exit 'continue breaks out of loop'
fi
print $i
done
) != foo ]]
fi
done
if [[ $(print -f "%b" "\a\n\v\b\r\f\E\03\\oo") != $'\a\n\v\b\r\f\E\03\\oo' ]]
then err_exit 'print -f "%b" not working'
fi
if [[ $(print -f "%P" "[^x].*b$") != '*[!x]*b' ]]
then err_exit 'print -f "%P" not working'
fi
then err_exit 'break labels not working'
fi
if [[ $(command -v if) != if ]]
then err_exit 'command -v not working'
fi
read -r var <<\!
!
if [[ $var != "" ]]
then err_exit "read -r of blank line not working"
fi
trap 'print HUP' HUP
if [[ $(trap) != "trap -- 'print HUP' HUP" ]]
then err_exit '$(trap) not working'
fi
if [[ $(trap -p HUP) != 'print HUP' ]]
then err_exit '$(trap -p HUP) not working'
fi
]] || err_exit 'SIGTERM not recognized'
]] || err_exit 'SIGTERM not recognized'
n=123
typeset -A base
for i in d i o u x X
then err_exit "printf %$i not working"
fi
done
then err_exit 'trap on EXIT not working'
fi
then err_exit 'trap on EXIT not being cleared'
fi
if [[ $(type test) != 'test is a shell builtin' ]]
then err_exit 'whence -v test not a builtin'
fi
builtin -d test
if [[ $(type test) == *builtin* ]]
then err_exit 'whence -v test after builtin -d incorrect'
fi
fi
then err_exit 'printf \0 not working'
fi
then err_exit 'printf %bx%s\n not working'
fi
then err_exit 'printf %10.%s\n not working'
fi
float x2=.0000625
then err_exit 'printf "%10.5E" not normalizing correctly'
fi
x2=.000000001
then err_exit 'printf "%g" not working correctly'
fi
#FIXME#($SHELL read -s foobar <<\!
#FIXME#testing
#FIXME#!
then err_exit 'printf is not processing formats beginning with + correctly'
fi
then err_exit "printf not exiting non-zero with conversion errors"
fi
then err_exit 'trap builtin terminating after --version'
fi
then err_exit 'set builtin terminating after --veresion'
fi
unset -f foobar
function foobar
{
print 'hello world'
}
OPTIND=1
then err_exit '\f...\f not working in getopts usage strings'
fi
then err_exit 'printf %H not working'
fi
then err_exit 'printf %R not working'
fi
then err_exit "printf '%..:c' not working"
fi
then err_exit "printf '%..*c' not working"
fi
then err_exit "printf '%..:s' not working"
fi
then err_exit "printf '%..*s' not working"
fi
# we won't get hit by the one second boundary twice, right?
err_exit 'printf "%T" now'
behead()
{
read line
}
print $'line1\nline2' | behead
then err_exit "read reading ahead on a pipe"
fi
read -n1 y <<!
!
if [[ $y != a ]]
then err_exit 'read -n1 not working'
fi
then err_exit 'read of incomplete line not working correctly'
fi
set -f
set -- *
if [[ $1 != '*' ]]
then err_exit 'set -f not working'
fi
false &
pid1=$!
pid2=$(
wait $pid1
print $!
)
wait $pid1
wait $pid2
set --noglob
IFS=,
env=
for v
do IFS=:
set -- $v
done
set --glob
then err_exit '"name=value exec -c ..." not working'
fi
then err_exit 'printf %2$s %1$s not working'
fi
((n=0))
for ((i=1; i<=n; i++))
do set -- ${ARGV[$i]}
OPTIND=0
do :
done
fi
done
unset a
!
[[ $b == d ]] || err_exit 'read -N1 here-document not working'
read -n3 a <<!
!
[[ $b == d ]] || err_exit 'read -N1 from pipe not working'
[[ $a == a ]] || err_exit 'read -n3 from pipe not working'
{
[[ $a == a ]] || err_exit 'read -n3 from fifo not working'
{
[[ $b == d ]] || err_exit 'read -N1 from fifo not working'
fi
function longline
{
integer i
for((i=0; i < $1; i++))
do print argument$i
done
}
# test command -x option
then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) 2> /dev/null)
done
command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
fi
# test command -x option with extra arguments
then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) one two three) #2> /dev/null)
done
command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
fi
# test for debug trap
[[ $(typeset -i i=0
while (( i <2))
do (( i++))
done
fi