######################################################################## # # # 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 # # http://www.opensource.org/licenses/cpl1.0.txt # # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # David Korn # # # ######################################################################## proc err_exit { print -u2 -n "\t" print -u2 -r $Command: @ARGV let Errors+=1 } alias err_exit='err_exit $LINENO' setvar Command = ${0##*/} integer Errors=0 setvar tmp = $(mktemp -dt) || do { err_exit mktemp -dt failed; exit 1; } trap "cd /; rm -rf $tmp" EXIT proc home # id { typeset IFS=: pwd=/etc/passwd set -o noglob if [[ -f $pwd ]] && grep -c "^$1:" $pwd > /dev/null { set -- $(grep "^$1:" $pwd) print -r -- $6 } else { print . } } setvar OLDPWD = '/bin' if [[ ~ != $HOME ]] { err_exit '~' not $HOME } setvar x = ~ if [[ $x != $HOME ]] { err_exit x=~ not $HOME } setvar x = "x:"~ if [[ $x != x:$HOME ]] { err_exit x=x:~ not x:$HOME } if [[ ~+ != $PWD ]] { err_exit '~' not $PWD } setvar x = "~+" if [[ $x != $PWD ]] { err_exit x=~+ not $PWD } if [[ ~- != $OLDPWD ]] { err_exit '~' not $PWD } setvar x = ~- if [[ $x != $OLDPWD ]] { err_exit x=~- not $OLDPWD } for u in [root Administrator] { setvar h = $(home $u) if [[ $h != . ]] { [[ ~$u -ef $h ]] || err_exit "~$u not $h" setvar x = "~$u" [[ $x -ef $h ]] || setvar x = ""~$u not $h"" break } } setvar x = ~g.r.emlin if [[ $x != '~g.r.emlin' ]] { err_exit "x=~g.r.emlin failed -- expected '~g.r.emlin', got '$x'" } setvar x = "~:"~ if [[ $x != "$HOME:$HOME" ]] { err_exit "x=~:~ failed, expected '$HOME:$HOME', got '$x'" } setvar HOME = '/' [[ ~ == / ]] || err_exit '~ should be /' [[ ~/foo == /foo ]] || err_exit '~/foo should be /foo when ~==/' print $'print ~+\n[[ $1 ]] && $0' > $tmp/tilde chmod +x $tmp/tilde setvar nl = '$'\n'' [[ $($tmp/tilde foo) == "$PWD$nl$PWD" ]] 2> /dev/null || err_exit 'tilde fails inside a script run by name' exit $((Errors))