1 #!/bin/bash
2
3 #### pushd/popd
4 set -o errexit
5 cd /
6 pushd /tmp
7 echo -n pwd=; pwd
8 popd
9 echo -n pwd=; pwd
10 ## status: 0
11 ## STDOUT:
12 /tmp /
13 pwd=/tmp
14 /
15 pwd=/
16 ## END
17 ## OK zsh STDOUT:
18 pwd=/tmp
19 pwd=/
20 ## END
21 ## N-I dash/mksh status: 127
22 ## N-I dash/mksh stdout-json: ""
23
24 #### dirs builtin
25 cd /
26 dirs
27 ## status: 0
28 ## STDOUT:
29 /
30 ## END
31
32 #### dirs -c to clear the stack
33 set -o errexit
34 cd /
35 pushd /tmp >/dev/null # zsh pushd doesn't print anything, but bash does
36 echo --
37 dirs
38 dirs -c
39 echo --
40 dirs
41 ## status: 0
42 ## STDOUT:
43 --
44 /tmp /
45 --
46 /tmp
47 ## END
48
49 #### dirs -v to print numbered stack, one entry per line
50 set -o errexit
51 cd /
52 pushd /tmp >/dev/null
53 echo --
54 dirs -v
55 pushd /lib >/dev/null
56 echo --
57 dirs -v
58 ## status: 0
59 ## STDOUT:
60 --
61 0 /tmp
62 1 /
63 --
64 0 /lib
65 1 /tmp
66 2 /
67 ## END
68 #
69 # zsh uses tabs
70 ## OK zsh stdout-json: "--\n0\t/tmp\n1\t/\n--\n0\t/lib\n1\t/tmp\n2\t/\n"
71
72 #### dirs -p to print one entry per line
73 set -o errexit
74 cd /
75 pushd /tmp >/dev/null
76 echo --
77 dirs -p
78 pushd /lib >/dev/null
79 echo --
80 dirs -p
81 ## STDOUT:
82 --
83 /tmp
84 /
85 --
86 /lib
87 /tmp
88 /
89 ## END
90
91 #### dirs -l to print in long format, no tilde prefix
92 # Can't use the OSH test harness for this because
93 # /home/<username> may be included in a path.
94 cd /
95 HOME=/tmp
96 mkdir -p $HOME/oil_test
97 pushd $HOME/oil_test >/dev/null
98 dirs
99 dirs -l
100 ## status: 0
101 ## STDOUT:
102 ~/oil_test /
103 /tmp/oil_test /
104 ## END
105
106 #### dirs to print using tilde-prefix format
107 cd /
108 HOME=/tmp
109 mkdir -p $HOME/oil_test
110 pushd $HOME/oil_test >/dev/null
111 dirs
112 ## stdout: ~/oil_test /
113 ## status: 0
114
115 #### dirs test converting true home directory to tilde
116 cd /
117 HOME=/tmp
118 mkdir -p $HOME/oil_test/$HOME
119 pushd $HOME/oil_test/$HOME >/dev/null
120 dirs
121 ## stdout: ~/oil_test/tmp /
122 ## status: 0
123
124 #### dirs don't convert to tilde when $HOME is substring
125 cd /
126 mkdir -p /tmp/oil_test
127 mkdir -p /tmp/oil_tests
128 HOME=/tmp/oil_test
129 pushd /tmp/oil_tests
130 dirs
131
132 #### dirs tilde test when $HOME is exactly $PWD
133 cd /
134 mkdir -p /tmp/oil_test
135 HOME=/tmp/oil_test
136 pushd $HOME
137 dirs
138 ## status: 0
139 # zsh doesn't duplicate the stack I guess.
140 ## OK zsh stdout-json: "~ /\n"
141 ## STDOUT:
142 ~ /
143 ~ /
144 ## END
145
146 #### dirs test of path alias `..`
147 cd /tmp
148 pushd .. >/dev/null
149 dirs
150 ## stdout: / /tmp
151 ## status: 0
152
153 #### dirs test of path alias `.`
154 cd /tmp
155 pushd . >/dev/null
156 dirs
157 ## stdout: /tmp /tmp
158 ## status: 0