Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/tilde.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
function err_exit
21
{
22
print -u2 -n "\t"
23
print -u2 -r $Command: "$@"
24
let Errors+=1
25
}
26
alias err_exit='err_exit $LINENO'
27
28
Command=${0##*/}
29
integer Errors=0
30
31
tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32
trap "cd /; rm -rf $tmp" EXIT
33
34
if $SHELL -c '[[ ~root == /* ]]'
35
then x=$(print -r -- ~root)
36
[[ $x == ~root ]] || err_exit '~user expanded in subshell prevent ~user from working'
37
fi
38
39
function home # id
40
{
41
typeset IFS=: pwd=/etc/passwd
42
set -o noglob
43
if [[ -f $pwd ]] && grep -c "^$1:" $pwd > /dev/null
44
then set -- $(grep "^$1:" $pwd)
45
print -r -- "$6"
46
else print .
47
fi
48
}
49
50
OLDPWD=/bin
51
if [[ ~ != $HOME ]]
52
then err_exit '~' not $HOME
53
fi
54
x=~
55
if [[ $x != $HOME ]]
56
then err_exit x=~ not $HOME
57
fi
58
x=x:~
59
if [[ $x != x:$HOME ]]
60
then err_exit x=x:~ not x:$HOME
61
fi
62
if [[ ~+ != $PWD ]]
63
then err_exit '~' not $PWD
64
fi
65
x=~+
66
if [[ $x != $PWD ]]
67
then err_exit x=~+ not $PWD
68
fi
69
if [[ ~- != $OLDPWD ]]
70
then err_exit '~' not $PWD
71
fi
72
x=~-
73
if [[ $x != $OLDPWD ]]
74
then err_exit x=~- not $OLDPWD
75
fi
76
for u in root Administrator
77
do h=$(home $u)
78
if [[ $h != . ]]
79
then [[ ~$u -ef $h ]] || err_exit "~$u not $h"
80
x=~$u
81
[[ $x -ef $h ]] || x="~$u not $h"
82
break
83
fi
84
done
85
x=~g.r.emlin
86
if [[ $x != '~g.r.emlin' ]]
87
then err_exit "x=~g.r.emlin failed -- expected '~g.r.emlin', got '$x'"
88
fi
89
x=~:~
90
if [[ $x != "$HOME:$HOME" ]]
91
then err_exit "x=~:~ failed, expected '$HOME:$HOME', got '$x'"
92
fi
93
HOME=/
94
[[ ~ == / ]] || err_exit '~ should be /'
95
[[ ~/foo == /foo ]] || err_exit '~/foo should be /foo when ~==/'
96
print $'print ~+\n[[ $1 ]] && $0' > $tmp/tilde
97
chmod +x $tmp/tilde
98
nl=$'\n'
99
[[ $($tmp/tilde foo) == "$PWD$nl$PWD" ]] 2> /dev/null || err_exit 'tilde fails inside a script run by name'
100
101
exit $((Errors<125?Errors:125))
102
103