io.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'
integer Errors=0
# cut here
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
then err_exit '<> not working right with read'
fi
then err_exit 'noclobber not causing exclusive open'
fi
set +o noclobber
fi
fi
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 -- "$(cat 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
[[ $( {
(
) & 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<&-
++EOF++
x=$(
{
print -n 1
print -n 3
} 2>&1
)
# 2004-12-20 redirction 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
{
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=$?
[[ -s /tmp/io.sh$$.1 || -s /tmp/io.sh$$.2 ]] && err_exit 'commands with standard output closed produce output'
$SHELL -c "$SHELL -c ': 3>&1' 1>&- 2>/dev/null" && err_exit 'closed standard output not passed to subshell'