########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# 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'
integer Errors=0
unset HISTFILE
function fun
{
while command exec 3>&1
do break
}
for ((i=3; i < 10; i++))
do
done
exec 3>&-
if [[ $(<file1) != $'foo\nbar' ]]
then err_exit 'append (>>) not working'
fi
set -o noclobber
exec 3<> file1
fi
then err_exit 'noclobber not causing exclusive open'
fi
set +o noclobber
FDFS=(
)
done
exec 3<> file1
exp='foo|bar'
*) semantics='failed' ;;
esac
[[ $semantics == @(${FDFS[fdfs].semantics}) ]] || err_exit "'4< ${FDFS[fdfs].dir}/3' $semantics semantics instead of ${FDFS[fdfs].semantics} -- expected '$exp', got '$got'"
fi
got=$(
{
print -n 1
print -n 3
} 2>&1
)
exp='1234|4'
*) semantics='failed' ;;
esac
[[ $semantics == @(${FDFS[fdfs].semantics}) ]] || err_exit "${FDFS[fdfs].dir}/N $semantics semantics instead of ${FDFS[fdfs].semantics} -- expected '$exp', got '$got'"
exec 0<&-
echo $(./close1)
!
print "echo abc" > close1
x=$(./close0)
if [[ $x != "abc" ]]
then err_exit "picked up file descriptor zero for opening script file"
fi
for ((i=0; i < 1100; i++))
read -u4
done
exit 0
!
$SHELL -c '
trap "rm -f in out" EXIT
for ((i = 0; i < 1000; i++))
do print -r -- "This is a test"
done > in
> out
exec 1<> out
builtin cat
print -r -- "$(<in)"
print hello
( exec 3<&- 4<&-)
exec 3<&- 4<&-
print world
!
cd ~- || err_exit "cd back failed"
unset x
exec <<!
!
read line
then err_exit 'file descriptor not restored after exec in subshell'
fi
exec 3>&- 4>&-
[[ $( {
(
) & wait
while read -r line
do print -r -- "$line"
done
} << !
line 1
line 2
line 3
# 2004-05-11 bug fix
trap "rm -f \$script" EXIT
exec 9> \$script
for ((i=3; i<9; i++))
done
for ((i=0; i < 60; i++))
done
print -u9 'print ok'
exec 9<&-
\$script
++EOF++
# 2004-12-20 redirection loss bug fix
function a
{
}
a
++EOF++
then err_exit "{n}<&0 not working with for loop"
fi
x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNSPQRSTUVWXYZ1234567890"
for ((i=0; i < 62; i++))
then (( $(3<#) == 0 )) || err_exit "not at position 0"
(( $(3<# ((EOF))) == 40*62 )) || err_exit "not at end-of-file"
command exec 3<# ((40*8)) || err_exit "absolute seek fails"
read -u3
[[ $(3<#) == $(3<# ((CUR)) ) ]] || err_exit '$(3<#)!=$(3<#((CUR)))'
command exec 3<# ((CUR+80))
read -u3
command exec 3<# ((EOF-80))
read -u3
command exec 3># ((80))
command exec 3># ((80))
read -u3
read -u3
command exec 3># ((EOF))
(( $(3<# ((CUR-0))) == 40*63 )) || err_exit "not at extended end-of-file"
command exec 3<# ((40*62))
read -u3
command exec 3<# ((0))
command exec 3<# *jjjj*
read -u3
[[ $(command exec 3<## *llll*) == {39}(k) ]] || err_exit "<## pattern not saving standard output"
read -u3
command exec 3<# *abc*
fi
command exec 3<&- || 'cannot close 3'
for ((i=0; i < 62; i++))
then (( $({n}<#) == 40*62)) || err_exit '$({n}<#) not working'
fi
fi
{
print -u2 || exit 2
print -u3 || exit 3
print -u4 || exit 4
print -u5 || exit 5
print -u6 || exit 6
print -u7 || exit 7
print -u8 || exit 8
print -u9 || exit 9
} 3> /dev/null 4> /dev/null 5> /dev/null 6> /dev/null 7> /dev/null 8> /dev/null 9> /dev/null' > /dev/null 2>&1
exitval=$?
$SHELL -c "$SHELL -c ': 3>&1' 1>&- 2>/dev/null" && err_exit 'closed standard output not passed to subshell'
{
return $?
}
do_it_all ; exit $?
fi
fi
fi
fi
fi
unset y
read -n1 y <<!
!
if [[ $y != a ]]
then err_exit 'read -n1 not working'
fi
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'
{
exp=a
got=$a
exp=b
got=$b
wait
{
got=$a
exp=d
got=$b
wait
fi
(
print -n 'prompt1: '
sleep .1
print line2
sleep .1
print -n 'prompt2: '
sleep .1
) | {
}
[[ $? == 0 ]] && err_exit 'should have timed out'
else lc_utf8=''
fi
integer i
set -- \
'a' 'bcd' 'a bcd' 'ab cd' \
'ab' 'cd' 'ab cd' 'ab cd' \
'abc' 'd' 'ab cd' 'ab cd' \
'abcd' '' 'ab cd' 'ab cd'
while (( $# >= 3 ))
do a=$1
b=$2
e[0]=$3
e[1]=$4
shift 4
for ((i = 0; i < 2; i++))
do g=$(LC_ALL=$lc_all $SHELL -c "{ print -n '$a'; sleep 0.2; print -n '$b'; sleep 0.2; } | { read ${o[i]} a; print -n \$a; read a; print -n \ \$a; }")
[[ $g == "${e[i]}" ]] || err_exit "LC_ALL=$lc_all read ${o[i]} from pipe '$a $b' failed -- expected '${e[i]}', got '$g'"
done
done
done
if [[ $lc_utf8 ]]
typeset -a c=( '' 'A' $'\303\274' $'\342\202\254' )
integer i w
typeset o
if (( ${#c[2]} == 1 && ${#c[3]} == 1 ))
then for i in 1 2 3
do for o in n N
do for w in 1 2 3
if [[ $o == N ]] && (( i > 1 ))
then e=''
else e=${c[w]}
fi
done
done
done
fi
fi
exec 3<&2
redirect 5>$file 2>&5
print -u5 -f 'This is a test\n'
exec 2<&3
exp=$'This is a test\nOK'
[[ $got == $exp ]] || err_exit "output garbled when stderr is duped -- expected $(printf %q "$exp"), got $(printf %q "$got")"
1<>; $file 1># ((5))
$SHELL -c "PS4=':2:'
set -x
printf ':1:A:'
print \$(:)
exp=$':1:A:\n:1:Z:'
[[ $exp == "$got" ]] || err_exit "standard output garbled -- expected $(printf %q "$exp"), got $(printf %q "$got")"
exp=$':2:printf :1:A:\n:2::\n:2:print\n:2:print :1:Z:'
[[ $exp == "$got" ]] || err_exit "standard error garbled -- expected $(printf %q "$exp"), got $(printf %q "$got")"
tmp=$tmp $SHELL 2> /dev/null -c 'exec 3<&1 ; exec 1<&- ; exec > $tmp/outfile;print foobar' || err_exit 'exec 1<&- causes failure'
[[ $(<$tmp/foobar) == $'hello world\ndone' ]] || err_exit '>; redirection not working for compound command'
[[ $(<$tmp/foobar) == 'hello world' ]] || err_exit '>; redirection not working with -c on a simple command'
for (( i=1; i < 50; i++ ))
if (( $? == 0 ))
then err_exit 'wrong error code with redirection'
break
fi
done
for i in 1
do :