########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2010 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 -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
unset HISTFILE
ulimit -c 0
print $1
!
) != hello ]]
then err_exit "${SHELL-ksh} -s not working"
fi
x=$(
set -e
false && print bad
print good
)
if [[ $x != good ]]
then err_exit 'sh -e not working'
fi
print $'PS1=""\nfunction env_hit\n{\n\tprint OK\n}' > $rc
if [[ ! -o privileged ]]
then
if [[ $g ]]
then
fi
then
err_exit "\$ENV file &>/dev/null does not redirect stderr -- expected one diagnostic line, got $got"
fi
fi
if [[ -o privileged ]]
then
err_exit 'privileged nointeractive shell reads $ENV file'
err_exit 'privileged -E reads $ENV file'
err_exit 'privileged +E reads $ENV file'
err_exit 'privileged --rc reads $ENV file'
err_exit 'privileged --norc reads $ENV file'
else
err_exit 'nointeractive shell reads $ENV file'
err_exit '-E ignores $ENV file'
err_exit '+E reads $ENV file'
err_exit '--rc ignores $ENV file'
err_exit '--norc reads $ENV file'
err_exit '-i ignores $ENV file'
fi
export ENV=
if [[ -o privileged ]]
then
err_exit 'privileged nointeractive shell reads $HOME/.kshrc file'
err_exit 'privileged -E ignores empty $ENV'
err_exit 'privileged +E reads $HOME/.kshrc file'
err_exit 'privileged --rc ignores empty $ENV'
err_exit 'privileged --norc reads $HOME/.kshrc file'
else
err_exit 'nointeractive shell reads $HOME/.kshrc file'
err_exit '-E ignores empty $ENV'
err_exit '+E reads $HOME/.kshrc file'
err_exit '--rc ignores empty $ENV'
err_exit '--norc reads $HOME/.kshrc file'
fi
unset ENV
if [[ -o privileged ]]
then
err_exit 'privileged nointeractive shell reads $HOME/.kshrc file'
err_exit 'privileged -E reads $HOME/.kshrc file'
err_exit 'privileged +E reads $HOME/.kshrc file'
err_exit 'privileged --rc reads $HOME/.kshrc file'
err_exit 'privileged --norc reads $HOME/.kshrc file'
else
err_exit 'nointeractive shell reads $HOME/.kshrc file'
err_exit '-E ignores $HOME/.kshrc file'
err_exit '+E reads $HOME/.kshrc file'
err_exit '--rc ignores $HOME/.kshrc file'
err_exit '--norc reads $HOME/.kshrc file'
fi
then cd $tmp
set -- **.c
[[ $* == $expected ]] ||
set -- **
[[ $* == $expected ]] ||
set -- **/*.c
[[ $* == $expected ]] ||
set -- **/bam.c
[[ $* == $expected ]] ||
cd ~-
fi
cd $tmp
t="<$$>.profile.<$$>"
echo "echo '$t'" > .profile
if [[ -o privileged ]]
then
err_exit 'privileged -l reads .profile'
err_exit 'privileged --login reads .profile'
err_exit 'privileged --login-shell reads .profile'
err_exit 'privileged --login_shell reads .profile'
err_exit 'privileged exec -a -ksh ksh reads .profile'
err_exit 'privileged ./-ksh reads .profile'
err_exit 'privileged ./-ksh -p reads .profile'
else
err_exit '-l ignores .profile'
err_exit '--login ignores .profile'
err_exit '--login-shell ignores .profile'
err_exit '--login_shell ignores .profile'
err_exit 'exec -a -ksh ksh 2>&1 ignores .profile'
err_exit './-ksh ignores .profile'
err_exit './-ksh -p does not ignore .profile'
fi
cd ~-
# { exec interactive login_shell restricted xtrace } in the following test
glob \
gmacs \
if [[ ! -o $opt ]]
fi
set --$old
done
do [[ -o $opt ]]
y=$?
n=$?
case $y$n in
10|01) ;;
esac
done
do if [[ -o ?$opt ]]
fi
fi
done
set -- $(set --state)
[[ $1 == set && $2 == --default ]] || err_exit "set --state failed -- expected 'set --default *', got '$1 $2 *'"
shift
restore=$*
shift
off=
for opt
esac
done
set $off
[[ $state == $default ]] || err_exit "set --state for default options failed: expected '$default', got '$state'"
set $restore
[[ $state == "set $restore" ]] || err_exit "set --state after restore failed: expected 'set $restore', got '$state'"
typeset -a pipeline
pipeline=(
)
set --nopipefail
for ((i = 0; i < ${#pipeline[@]}; i++ ))
do eval ${pipeline[i].command}
status=$?
expected=${pipeline[i].nopipefail}
done
ftt=0
set --pipefail
for ((i = 0; i < ${#pipeline[@]}; i++ ))
do eval ${pipeline[i].command}
status=$?
fi
done
then exp=10
got=$(for((n=1;n<exp;n++))do $SHELL --pipefail -c '(sleep 0.1;false)|true|true' && break; done; print $n)
[[ $got == $exp ]] || err_exit "--pipefail -c '(sleep 0.1;false)|true|true' fails with exit status 0 (after $got/$exp iterations)"
fi
echo=$(whence -p echo)
for ((i=0; i < 20; i++))
do if ! x=$(true | $echo 123)
then err_exit 'command substitution with wrong exit status with pipefai'
break
fi
done
(
set -o pipefail
false | true
$SHELL -c 'set -o pipefail; false | $(whence -p true);' && err_exit 'pipefail not returning failure with sh -c'
exp='1212 or 1221'
got=$(
set --pipefail
print $'1\n2' |
while read i
fi
done
wait
)
[[ $got == @((12|21)(12|21)) ]] || err_exit "& job delayed by --pipefail, expected '$exp', got '$got'"
for i in i l r s D E a b e f h k n t u v x B C G H
[[ \$- == *$i* ]] || exit 1
++EOF++
done
integer j=0
for i in interactive login restricted allexport notify errexit \
do HOME=$tmp ENV= $SHELL -o $i >/dev/null 2>&1 <<- ++EOF++ || err_exit "option $i not equivalent to ${letters:j:1}"
[[ \$- == *${letters:j:1}* ]] || exit 1
++EOF++
((j++))
done
export ENV=
do got=$( ( HISTFILE=$histfile $SHELL -ic $'unset '$var$'\nfunction foo\n{\ncat\n}\ntype foo\nexit' ) 2>&1 )
[[ $got == "$exp" ]] || err_exit "function definition inside (...) with $var unset fails -- got '$got', expected '$exp'"
got=$( { HISTFILE=$histfile $SHELL -ic $'unset '$var$'\nfunction foo\n{\ncat\n}\ntype foo\nexit' ;} 2>&1 )
[[ $got == "$exp" ]] || err_exit "function definition inside {...;} with $var unset fails -- got '$got', expected '$exp'"
done
( unset HISTFILE; $SHELL -ic "HISTFILE=$histfile" 2>/dev/null ) || err_exit "setting HISTFILE when not in environment fails"
# the next tests loop on all combinations of
# { SUB PAR CMD ADD }
SUB=(
)
PAR=(
)
cd $tmp
exp='Killed'
for ((S=0; S<${#SUB[@]}; S++))
do for ((P=0; P<${#PAR[@]}; P++))
do for ((C=0; C<${#CMD[@]}; C++))
do for ((A=0; A<${#ADD[@]}; A++))
do cmd="${SUB[S].BEG}${PAR[P].BEG}${CMD[C]}${PAR[P].END} 2>&1${ADD[A]}${SUB[S].END}"
done
done
done
done
$SHELL 2> /dev/null -c '(; true ;)' || err_exit 'leading ; causes syntax error in parenthesis group'
tst=$!
spy=$!
status=$?
else err_exit "pipefail pipeline bypasses SIGPIPE and hangs"
fi
wait