1da2e3ebdSchin######################################################################## 2da2e3ebdSchin# # 3da2e3ebdSchin# This software is part of the ast package # 4*3e14f97fSRoger A. Faulkner# Copyright (c) 1982-2010 AT&T Intellectual Property # 5da2e3ebdSchin# and is licensed under the # 6da2e3ebdSchin# Common Public License, Version 1.0 # 77c2fbfb3SApril Chin# by AT&T Intellectual Property # 8da2e3ebdSchin# # 9da2e3ebdSchin# A copy of the License is available at # 10da2e3ebdSchin# http://www.opensource.org/licenses/cpl1.0.txt # 11da2e3ebdSchin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 12da2e3ebdSchin# # 13da2e3ebdSchin# Information and Software Systems Research # 14da2e3ebdSchin# AT&T Research # 15da2e3ebdSchin# Florham Park NJ # 16da2e3ebdSchin# # 17da2e3ebdSchin# David Korn <dgk@research.att.com> # 18da2e3ebdSchin# # 19da2e3ebdSchin######################################################################## 20da2e3ebdSchinfunction err_exit 21da2e3ebdSchin{ 22da2e3ebdSchin print -u2 -n "\t" 23da2e3ebdSchin print -u2 -r $Command: "$@" 24da2e3ebdSchin let Errors+=1 25da2e3ebdSchin} 26da2e3ebdSchinalias err_exit='err_exit $LINENO' 27da2e3ebdSchin 2834f9b3eeSRoland MainzCommand=${0##*/} 2934f9b3eeSRoland Mainzinteger Errors=0 3034f9b3eeSRoland Mainz 3134f9b3eeSRoland Mainztmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 3234f9b3eeSRoland Mainztrap "cd /; rm -rf $tmp" EXIT 3334f9b3eeSRoland Mainz 34da2e3ebdSchinfunction home # id 35da2e3ebdSchin{ 36da2e3ebdSchin typeset IFS=: pwd=/etc/passwd 37da2e3ebdSchin set -o noglob 38da2e3ebdSchin if [[ -f $pwd ]] && grep -c "^$1:" $pwd > /dev/null 39da2e3ebdSchin then set -- $(grep "^$1:" $pwd) 40da2e3ebdSchin print -r -- "$6" 41da2e3ebdSchin else print . 42da2e3ebdSchin fi 43da2e3ebdSchin} 44da2e3ebdSchin 45da2e3ebdSchinOLDPWD=/bin 46da2e3ebdSchinif [[ ~ != $HOME ]] 47da2e3ebdSchinthen err_exit '~' not $HOME 48da2e3ebdSchinfi 49da2e3ebdSchinx=~ 50da2e3ebdSchinif [[ $x != $HOME ]] 51da2e3ebdSchinthen err_exit x=~ not $HOME 52da2e3ebdSchinfi 53da2e3ebdSchinx=x:~ 54da2e3ebdSchinif [[ $x != x:$HOME ]] 55da2e3ebdSchinthen err_exit x=x:~ not x:$HOME 56da2e3ebdSchinfi 57da2e3ebdSchinif [[ ~+ != $PWD ]] 58da2e3ebdSchinthen err_exit '~' not $PWD 59da2e3ebdSchinfi 60da2e3ebdSchinx=~+ 61da2e3ebdSchinif [[ $x != $PWD ]] 62da2e3ebdSchinthen err_exit x=~+ not $PWD 63da2e3ebdSchinfi 64da2e3ebdSchinif [[ ~- != $OLDPWD ]] 65da2e3ebdSchinthen err_exit '~' not $PWD 66da2e3ebdSchinfi 67da2e3ebdSchinx=~- 68da2e3ebdSchinif [[ $x != $OLDPWD ]] 69da2e3ebdSchinthen err_exit x=~- not $OLDPWD 70da2e3ebdSchinfi 71da2e3ebdSchinfor u in root Administrator 72da2e3ebdSchindo h=$(home $u) 73da2e3ebdSchin if [[ $h != . ]] 74da2e3ebdSchin then [[ ~$u -ef $h ]] || err_exit "~$u not $h" 75da2e3ebdSchin x=~$u 7634f9b3eeSRoland Mainz [[ $x -ef $h ]] || x="~$u not $h" 77da2e3ebdSchin break 78da2e3ebdSchin fi 79da2e3ebdSchindone 8034f9b3eeSRoland Mainzx=~g.r.emlin 8134f9b3eeSRoland Mainzif [[ $x != '~g.r.emlin' ]] 8234f9b3eeSRoland Mainzthen err_exit "x=~g.r.emlin failed -- expected '~g.r.emlin', got '$x'" 83da2e3ebdSchinfi 84da2e3ebdSchinx=~:~ 85da2e3ebdSchinif [[ $x != "$HOME:$HOME" ]] 8634f9b3eeSRoland Mainzthen err_exit "x=~:~ failed, expected '$HOME:$HOME', got '$x'" 87da2e3ebdSchinfi 88da2e3ebdSchinHOME=/ 89da2e3ebdSchin[[ ~ == / ]] || err_exit '~ should be /' 90da2e3ebdSchin[[ ~/foo == /foo ]] || err_exit '~/foo should be /foo when ~==/' 9134f9b3eeSRoland Mainzprint $'print ~+\n[[ $1 ]] && $0' > $tmp/tilde 9234f9b3eeSRoland Mainzchmod +x $tmp/tilde 937c2fbfb3SApril Chinnl=$'\n' 9434f9b3eeSRoland Mainz[[ $($tmp/tilde foo) == "$PWD$nl$PWD" ]] 2> /dev/null || err_exit 'tilde fails inside a script run by name' 95da2e3ebdSchinexit $((Errors)) 96