blob: 50f19e98a7240555299e5200ce3bffce971ed72f [file] [log] [blame]
Jari Aaltod166f041997-06-05 14:59:13 +00001# this is needed because posix mode restricts tilde expansion to assignment
2# statements preceding a command, instead of the default of expanding all
3# assignment statements on the line (e.g., after `export'). Without this,
4# the next-to-last test fails
5set +o posix
6
Jari Aalto726f6381996-08-26 18:22:31 +00007HOME=/usr/xyz
Jari Aaltoccc6cda1996-12-23 17:02:34 +00008SHELL=~/bash
Jari Aalto726f6381996-08-26 18:22:31 +00009echo ~ch\et
Jari Aaltoccc6cda1996-12-23 17:02:34 +000010echo ~/"foo"
Jari Aalto726f6381996-08-26 18:22:31 +000011echo "~chet"/"foo"
12echo \~chet/"foo"
13echo \~chet/bar
14echo ~\chet/bar
15echo ~chet""/bar
16echo ":~chet/"
17echo abcd~chet
18echo "SHELL=~/bash"
Jari Aaltoccc6cda1996-12-23 17:02:34 +000019echo $SHELL
Jari Aalto726f6381996-08-26 18:22:31 +000020echo abcd:~chet
Jari Aaltoccc6cda1996-12-23 17:02:34 +000021path=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin
22echo $path
23
24cd /usr
25cd /tmp
26echo ~-
27echo ~+
28
29XPATH=/bin:/usr/bin:.
30
31# yes tilde expansion
32PPATH=$XPATH:~/bin
33echo "$PPATH"
34
35# no tilde expansion
36PPATH="$XPATH:~/bin"
37echo "$PPATH"
38
39# yes tilde expansion
40export PPATH=$XPATH:~/bin
41echo "$PPATH"
Jari Aaltod166f041997-06-05 14:59:13 +000042declare -x PPATH=$XPATH:~/bin
43echo "$PPATH"
Jari Aaltoccc6cda1996-12-23 17:02:34 +000044
45# no tilde expansion
46export PPATH="$XPATH:~/bin"
47echo "$PPATH"
Jari Aaltod166f041997-06-05 14:59:13 +000048declare -x PPATH="$XPATH:~/bin"
49echo "$PPATH"
50
Chet Rameyac50fba2014-02-26 09:36:43 -050051printf "%q\n" '~'
52
Jari Aaltod166f041997-06-05 14:59:13 +000053# more tests of tilde expansion when executing case commands
54case ~ in
55$HOME) echo ok 1;;
56*) echo bad 1 ;;
57esac
58
59case ~ in
60~) echo ok 2 ;;
61\~) echo bad 2a ;;
62*) echo bad 2b ;;
63esac
64
65case $unset in
66"") echo ok 3 ;;
67*) echo bad 3 ;;
68esac
Jari Aalto06285672006-10-10 14:15:34 +000069
70USER=root # should exist just about everywhere
71echo ~$USER