subshell.sh revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2008 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# 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 -u$Error_fd -n "\t"
}
alias err_exit='err_exit $LINENO'
z=()
val='(
typeset -a bar=(
[0]=hello
[2]=world
[1]=(
x=4
y=5
)
)
typeset -A foo=(
[one]=hello
[three]=hi
[two]=(
x=3
y=4
)
)
)'
[[ ${z.bar[1]} == $'(\n\tx=12\n\ty=5\n)' ]] || err_exit 'reassign array simple to compound variable fails'
eval val="$z"
(
)
eval val="$z"
(
false
[[ ${z.foo[two]} == ok ]] || err_exit 'associative array assignment to compound variable in subshell not working'
[[ ${z.bar[1]} == yes ]] || err_exit 'index array assignment to compound variable in subshell not working'
)
x=(
)
eval val="$x"
(
unset x.foo
)
unset l
(
l=( a=1 b="BE" )
)
Error_fd=9
done
do $SHELL -c '
{
kill -KILL $$
} &
print ${#1}
kill $!
(( no == (BS * nb) )) || err_exit "shell hangs on command substitution output size >= $BS*$nb with write size $bs -- expected $((BS*nb)), got ${no:-0}"
done
# this time with redirection on the trailing command
do $SHELL -c '
{
sleep 2
kill -KILL $$
} &
print ${#1}
kill $!
(( no == (BS * nb) )) || err_exit "shell hangs on command substitution output size >= $BS*$nb with write size $bs and trailing redirection -- expected $((BS*nb)), got ${no:-0}"
done
# exercise command substitutuion trailing newline logic w.r.t. pipe vs. tmp file io
set -- \
'post-line print' \
'$TEST_unset; ($TEST_fork; print 1); print' \
1 \
'pre-line print' \
'$TEST_unset; ($TEST_fork; print); print 1' \
$'\n1' \
'multiple pre-line print' \
'$TEST_unset; ($TEST_fork; print); print; ($TEST_fork; print 1); print' \
$'\n\n1' \
'multiple post-line print' \
'$TEST_unset; ($TEST_fork; print 1); print; ($TEST_fork; print); print' \
1 \
'intermediate print' \
'$TEST_unset; ($TEST_fork; print 1); print; ($TEST_fork; print 2); print' \
$'1\n\n2' \
'simple variable' \
'$TEST_unset; ($TEST_fork; l=2; print "$l"); print $l' \
2 \
'compound variable' \
'$TEST_unset; ($TEST_fork; l=(a=2 b="BE"); print "$l"); print $l' \
$'(\n\ta=2\n\tb=BE\n)' \
export TEST_fork TEST_unset
while (( $# >= 3 ))
do txt=$1
cmd=$2
exp=$3
shift 3
then err_exit "${TEST_shell/*-c/\$SHELL -c} ${TEST_unset:+unset }${TEST_fork:+fork }$txt print failed"
err_exit "${TEST_shell/*-c/\$SHELL -c} ${TEST_unset:+unset }${TEST_fork:+fork }$txt command substitution failed -- expected $EXP, got $GOT"
fi
done
done
done
done
{
sleep 32
kill -KILL $$
} &
for v in $(set | sed "s/=.*//")
do command unset $v
done
typeset -Z5 I
for ((I = 0; I < 1024; I++))
do eval A$I=1234567890
done
a=$(set 2>&1)
print ok
kill -KILL $!
do
r=$($SHELL -c '
{
sleep 2
kill -KILL $$
} &
kill $!
print ok
')
done
done
done
done
done
exit $Errors