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