blob: 60a2de0aa8f69572cbda4b03d10af3b7fc6846b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
########################################################################
# #
# 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 #
# 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 <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
print -u2 -r $Command: "$@"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
function home # id
{
typeset IFS=: pwd=/etc/passwd
set -o noglob
if [[ -f $pwd ]] && grep -c "^$1:" $pwd > /dev/null
then set -- $(grep "^$1:" $pwd)
print -r -- "$6"
else print .
fi
}
Command=${0##*/}
integer Errors=0
OLDPWD=/bin
if [[ ~ != $HOME ]]
then err_exit '~' not $HOME
fi
x=~
if [[ $x != $HOME ]]
then err_exit x=~ not $HOME
fi
x=x:~
if [[ $x != x:$HOME ]]
then err_exit x=x:~ not x:$HOME
fi
if [[ ~+ != $PWD ]]
then err_exit '~' not $PWD
fi
x=~+
if [[ $x != $PWD ]]
then err_exit x=~+ not $PWD
fi
if [[ ~- != $OLDPWD ]]
then err_exit '~' not $PWD
fi
x=~-
if [[ $x != $OLDPWD ]]
then err_exit x=~- not $OLDPWD
fi
for u in root Administrator
do h=$(home $u)
if [[ $h != . ]]
then [[ ~$u -ef $h ]] || err_exit "~$u not $h"
x=~$u
[[ $x -ef $h ]] || "x=~$u not $h"
break
fi
done
x=~%%
if [[ $x != '~%%' ]]
then err_exit 'x='~%%' not '~%%
fi
x=~:~
if [[ $x != "$HOME:$HOME" ]]
then err_exit x=~:~ not $HOME:$HOME
fi
HOME=/
[[ ~ == / ]] || err_exit '~ should be /'
trap 'rm -rf /tmp/kshtilde$$' EXIT
[[ ~/foo == /foo ]] || err_exit '~/foo should be /foo when ~==/'
print $'print ~+\n[[ $1 ]] && $0' > /tmp/kshtilde$$
chmod +x /tmp/kshtilde$$
nl=$'\n'
[[ $(/tmp/kshtilde$$ foo) == "$PWD$nl$PWD" ]] 2> /dev/null || err_exit 'tilde fails inside a script run by name'
exit $((Errors))
|