]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/tilde.tests
bash-5.1 beta release
[thirdparty/bash.git] / tests / tilde.tests
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 #
14 wdir=$PWD
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
19 set +o posix
20
21 HOME=/usr/xyz
22 SHELL=~/bash
23 echo ~ch\et
24 echo ~/"foo"
25 echo "~chet"/"foo"
26 echo \~chet/"foo"
27 echo \~chet/bar
28 echo ~\chet/bar
29 echo ~chet""/bar
30 echo ":~chet/"
31 echo abcd~chet
32 echo "SHELL=~/bash"
33 echo $SHELL
34 echo abcd:~chet
35 path=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin
36 echo $path
37
38 cd /usr
39 cd /tmp
40 echo ~-
41 echo ~+
42
43 XPATH=/bin:/usr/bin:.
44
45 # yes tilde expansion
46 PPATH=$XPATH:~/bin
47 echo "$PPATH"
48
49 # no tilde expansion
50 PPATH="$XPATH:~/bin"
51 echo "$PPATH"
52
53 # yes tilde expansion
54 export PPATH=$XPATH:~/bin
55 echo "$PPATH"
56 declare -x PPATH=$XPATH:~/bin
57 echo "$PPATH"
58
59 # no tilde expansion
60 export PPATH="$XPATH:~/bin"
61 echo "$PPATH"
62 declare -x PPATH="$XPATH:~/bin"
63 echo "$PPATH"
64
65 printf "%q\n" '~'
66
67 # more tests of tilde expansion when executing case commands
68 case ~ in
69 $HOME) echo ok 1;;
70 *) echo bad 1 ;;
71 esac
72
73 case ~ in
74 ~) echo ok 2 ;;
75 \~) echo bad 2a ;;
76 *) echo bad 2b ;;
77 esac
78
79 case $unset in
80 "") echo ok 3 ;;
81 *) echo bad 3 ;;
82 esac
83
84 USER=root # should exist just about everywhere
85 echo ~$USER
86
87 cd "$wdir"
88
89 echo foo=bar:~
90 set -o posix; echo foo=bar:~
91
92 exit 0