options.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 -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
unset HISTFILE
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 workuing'
fi
print $'PS1=""\nfunction env_hit\n{\n\tprint OK\n}' > $rc
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
set -- **.c
[[ $* == $expected ]] ||
set -- **
[[ $* == $expected ]] ||
set -- **/*.c
[[ $* == $expected ]] ||
set -- **/bam.c
[[ $* == $expected ]] ||
cd ~-
fi
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 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'"
false | true | true || err_exit 'pipe not exiting exit value of last element'
true | true | false && err_exit 'pipe not exiting false'
set -o pipefail
false | true | true && err_exit 'pipe with first not failing with pipefail'
true | false | true && err_exit 'pipe middle not failing with pipefail'
true | true | false && err_exit 'pipe last not failing with pipefail'
(
set -o pipefail
false | true
$SHELL -c 'set -o pipefail; false | $(whence -p true);' && err_exit 'pipefail not returning failure with sh -c'
[[ $( set -o pipefail
print $'1\n2' |
while read i
fi
done
trap 'rm -f /tmp/.profile' EXIT
for i in i l r s D E a b e f h k n r t u v x B C G H
[[ \$- == *$i* ]] || exit 1
++EOF++
done
integer j=0
do HOME=/tmp ENV= $SHELL -o $i 2> /dev/null <<- ++EOF++ || err_exit "option $i not equivalent to ${letters:j:1}"
++EOF++
((j++))
done