]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/tilde.tests
bash-5.1 beta release
[thirdparty/bash.git] / tests / tilde.tests
CommitLineData
712f80b0
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
d233b485 14wdir=$PWD
d166f048
JA
15# this is needed because posix mode restricts tilde expansion to assignment
16# statements preceding a command, instead of the default of expanding all
17# assignment statements on the line (e.g., after `export'). Without this,
18# the next-to-last test fails
19set +o posix
20
726f6388 21HOME=/usr/xyz
ccc6cda3 22SHELL=~/bash
726f6388 23echo ~ch\et
ccc6cda3 24echo ~/"foo"
726f6388
JA
25echo "~chet"/"foo"
26echo \~chet/"foo"
27echo \~chet/bar
28echo ~\chet/bar
29echo ~chet""/bar
30echo ":~chet/"
31echo abcd~chet
32echo "SHELL=~/bash"
ccc6cda3 33echo $SHELL
726f6388 34echo abcd:~chet
ccc6cda3
JA
35path=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin
36echo $path
37
38cd /usr
39cd /tmp
40echo ~-
41echo ~+
42
43XPATH=/bin:/usr/bin:.
44
45# yes tilde expansion
46PPATH=$XPATH:~/bin
47echo "$PPATH"
48
49# no tilde expansion
50PPATH="$XPATH:~/bin"
51echo "$PPATH"
52
53# yes tilde expansion
54export PPATH=$XPATH:~/bin
55echo "$PPATH"
d166f048
JA
56declare -x PPATH=$XPATH:~/bin
57echo "$PPATH"
ccc6cda3
JA
58
59# no tilde expansion
60export PPATH="$XPATH:~/bin"
61echo "$PPATH"
d166f048
JA
62declare -x PPATH="$XPATH:~/bin"
63echo "$PPATH"
64
ac50fbac
CR
65printf "%q\n" '~'
66
d166f048
JA
67# more tests of tilde expansion when executing case commands
68case ~ in
69$HOME) echo ok 1;;
70*) echo bad 1 ;;
71esac
72
73case ~ in
74~) echo ok 2 ;;
75\~) echo bad 2a ;;
76*) echo bad 2b ;;
77esac
78
79case $unset in
80"") echo ok 3 ;;
81*) echo bad 3 ;;
82esac
0628567a
JA
83
84USER=root # should exist just about everywhere
85echo ~$USER
d233b485
CR
86
87cd "$wdir"
3eb0018e
CR
88
89echo foo=bar:~
90set -o posix; echo foo=bar:~
91
d233b485 92exit 0