improve of cmpl.
[bush.git] / tests / tilde.tests
blob748b779a9aac7aebc9e87eaacb1d631d1e47adac
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.
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.
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/>.
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
21 HOME=/usr/xyz
22 SHELL=~/bush
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=~/bush"
33 echo $SHELL
34 echo abcd:~chet
35 path=/usr/ucb:/bin:~/bin:~/tmp/bin:/usr/bin
36 echo $path
38 cd /usr
39 cd /tmp
40 echo ~-
41 echo ~+
43 XPATH=/bin:/usr/bin:.
45 # yes tilde expansion
46 PPATH=$XPATH:~/bin
47 echo "$PPATH"
49 # no tilde expansion
50 PPATH="$XPATH:~/bin"
51 echo "$PPATH"
53 # yes tilde expansion
54 export PPATH=$XPATH:~/bin
55 echo "$PPATH"
56 declare -x PPATH=$XPATH:~/bin
57 echo "$PPATH"
59 # no tilde expansion
60 export PPATH="$XPATH:~/bin"
61 echo "$PPATH"
62 declare -x PPATH="$XPATH:~/bin"
63 echo "$PPATH"
65 printf "%q\n" '~'
67 # more tests of tilde expansion when executing case commands
68 case ~ in
69 $HOME)  echo ok 1;;
70 *) echo bad 1 ;;
71 esac
73 case ~ in
74 ~)      echo ok 2 ;;
75 \~)     echo bad 2a ;;
76 *)      echo bad 2b ;;
77 esac
79 case $unset in
80 "")     echo ok 3 ;;
81 *)      echo bad 3 ;;
82 esac
84 USER=root               # should exist just about everywhere
85 echo ~$USER
87 cd "$wdir"
89 echo foo=bar:~
90 set -o posix; echo foo=bar:~
92 exit 0