| 1 | ## tags: dev-minimal interactive
|
| 2 | ## compare_shells: bash
|
| 3 |
|
| 4 | #### 'exit' in oshrc (regression)
|
| 5 | cat >$TMP/oshrc <<EOF
|
| 6 | echo one
|
| 7 | exit 42
|
| 8 | echo two
|
| 9 | EOF
|
| 10 | $SH --rcfile $TMP/oshrc -i -c 'echo hello'
|
| 11 | ## status: 42
|
| 12 | ## STDOUT:
|
| 13 | one
|
| 14 | ## END
|
| 15 |
|
| 16 | #### fatal errors continue
|
| 17 | # NOTE: tried here doc, but sys.stdin.isatty() fails. Could we fake it?
|
| 18 | $SH --rcfile /dev/null -i -c '
|
| 19 | echo $(( 1 / 0 ))
|
| 20 | echo one
|
| 21 | exit 42
|
| 22 | '
|
| 23 | ## status: 42
|
| 24 | ## STDOUT:
|
| 25 | one
|
| 26 | ## END
|
| 27 |
|
| 28 | #### interactive shell loads rcfile (when combined with -c)
|
| 29 | $SH -c 'echo 1'
|
| 30 | cat >$TMP/rcfile <<EOF
|
| 31 | echo RCFILE
|
| 32 | EOF
|
| 33 | $SH --rcfile $TMP/rcfile -i -c 'echo 2'
|
| 34 | ## STDOUT:
|
| 35 | 1
|
| 36 | RCFILE
|
| 37 | 2
|
| 38 | ## END
|
| 39 |
|
| 40 | #### --rcfile with parse error - shell is executed anyway
|
| 41 | cat >$TMP/rcfile <<EOF
|
| 42 | echo RCFILE; ( echo
|
| 43 | EOF
|
| 44 |
|
| 45 | $SH --rcfile $TMP/rcfile -i -c 'echo flag -c'
|
| 46 | echo status=$?
|
| 47 |
|
| 48 | ## STDOUT:
|
| 49 | flag -c
|
| 50 | status=0
|
| 51 | ## END
|
| 52 |
|
| 53 | #### interactive shell loads files in rcdir (when combined with -c)
|
| 54 |
|
| 55 | $SH -c 'echo A'
|
| 56 |
|
| 57 | cat >$TMP/rcfile <<EOF
|
| 58 | echo 'rcfile first'
|
| 59 | EOF
|
| 60 |
|
| 61 | mkdir -p $TMP/rcdir
|
| 62 |
|
| 63 | cat >$TMP/rcdir/file1 <<EOF
|
| 64 | echo rcdir 1
|
| 65 | EOF
|
| 66 |
|
| 67 | cat >$TMP/rcdir/file2 <<EOF
|
| 68 | echo rcdir 2
|
| 69 | EOF
|
| 70 |
|
| 71 | # --rcdir only
|
| 72 | $SH --rcdir $TMP/rcdir -i -c 'echo B'
|
| 73 |
|
| 74 | $SH --rcfile $TMP/rcfile --rcdir $TMP/rcdir -i -c 'echo C'
|
| 75 |
|
| 76 | ## STDOUT:
|
| 77 | A
|
| 78 | rcdir 1
|
| 79 | rcdir 2
|
| 80 | B
|
| 81 | rcfile first
|
| 82 | rcdir 1
|
| 83 | rcdir 2
|
| 84 | C
|
| 85 | ## END
|
| 86 |
|
| 87 | ## N-I bash status: 2
|
| 88 | ## N-I bash STDOUT:
|
| 89 | A
|
| 90 | ## END
|
| 91 |
|
| 92 | #### nonexistent --rcdir is ignored
|
| 93 | case $SH in bash) exit ;; esac
|
| 94 |
|
| 95 | $SH --rcdir $TMP/__does-not-exist -i -c 'echo hi'
|
| 96 | echo status=$?
|
| 97 |
|
| 98 | ## STDOUT:
|
| 99 | hi
|
| 100 | status=0
|
| 101 | ## END
|
| 102 | ## N-I bash STDOUT:
|
| 103 | ## END
|
| 104 |
|
| 105 | #### shell doesn't load rcfile/rcdir if --norc is given
|
| 106 |
|
| 107 | $SH -c 'echo A'
|
| 108 |
|
| 109 | cat >$TMP/rcfile <<EOF
|
| 110 | echo rcfile
|
| 111 | EOF
|
| 112 |
|
| 113 | mkdir -p $TMP/rcdir
|
| 114 | cat >$TMP/rcdir/file1 <<EOF
|
| 115 | echo rcdir 1
|
| 116 | EOF
|
| 117 |
|
| 118 | cat >$TMP/rcdir/file2 <<EOF
|
| 119 | echo rcdir 2
|
| 120 | EOF
|
| 121 |
|
| 122 | $SH --norc --rcfile $TMP/rcfile -c 'echo C'
|
| 123 | case $SH in bash) exit ;; esac
|
| 124 |
|
| 125 | $SH --norc --rcfile $TMP/rcfile --rcdir $TMP/rcdir -c 'echo D'
|
| 126 |
|
| 127 | ## STDOUT:
|
| 128 | A
|
| 129 | C
|
| 130 | D
|
| 131 | ## END
|
| 132 | ## OK bash STDOUT:
|
| 133 | A
|
| 134 | C
|
| 135 | ## END
|
| 136 |
|
| 137 |
|
| 138 | #### interactive shell runs PROMPT_COMMAND after each command
|
| 139 | export PS1='' # OSH prints prompt to stdout
|
| 140 |
|
| 141 | case $SH in
|
| 142 | *bash|*osh)
|
| 143 | $SH --rcfile /dev/null -i << EOF
|
| 144 | PROMPT_COMMAND='echo PROMPT'
|
| 145 | echo one
|
| 146 | echo two
|
| 147 | EOF
|
| 148 | ;;
|
| 149 | esac
|
| 150 |
|
| 151 | # Paper over difference with OSH
|
| 152 | case $SH in *bash) echo '^D';; esac
|
| 153 |
|
| 154 | ## STDOUT:
|
| 155 | PROMPT
|
| 156 | one
|
| 157 | PROMPT
|
| 158 | two
|
| 159 | PROMPT
|
| 160 | ^D
|
| 161 | ## END
|
| 162 |
|
| 163 |
|
| 164 | #### parse error in PROMPT_COMMAND
|
| 165 | export PS1='' # OSH prints prompt to stdout
|
| 166 |
|
| 167 | case $SH in
|
| 168 | *bash|*osh)
|
| 169 | $SH --rcfile /dev/null -i << EOF
|
| 170 | PROMPT_COMMAND=';'
|
| 171 | echo one
|
| 172 | echo two
|
| 173 | EOF
|
| 174 | ;;
|
| 175 | esac
|
| 176 |
|
| 177 | # Paper over difference with OSH
|
| 178 | case $SH in *bash) echo '^D';; esac
|
| 179 |
|
| 180 | ## STDOUT:
|
| 181 | one
|
| 182 | two
|
| 183 | ^D
|
| 184 | ## END
|
| 185 |
|
| 186 | #### runtime error in PROMPT_COMMAND
|
| 187 | export PS1='' # OSH prints prompt to stdout
|
| 188 |
|
| 189 | case $SH in
|
| 190 | *bash|*osh)
|
| 191 | $SH --rcfile /dev/null -i << 'EOF'
|
| 192 | PROMPT_COMMAND='echo PROMPT $(( 1 / 0 ))'
|
| 193 | echo one
|
| 194 | echo two
|
| 195 | EOF
|
| 196 | ;;
|
| 197 | esac
|
| 198 |
|
| 199 | # Paper over difference with OSH
|
| 200 | case $SH in *bash) echo '^D';; esac
|
| 201 |
|
| 202 | ## STDOUT:
|
| 203 | one
|
| 204 | two
|
| 205 | ^D
|
| 206 | ## END
|
| 207 |
|
| 208 | #### Error message with bad oshrc file (currently ignored)
|
| 209 | cd $TMP
|
| 210 | echo 'foo >' > bad_oshrc
|
| 211 |
|
| 212 | $SH --rcfile bad_oshrc -i -c 'echo hi' 2>stderr.txt
|
| 213 | echo status=$?
|
| 214 |
|
| 215 | # bash prints two lines
|
| 216 | grep --max-count 1 -o 'bad_oshrc:' stderr.txt
|
| 217 |
|
| 218 | ## STDOUT:
|
| 219 | hi
|
| 220 | status=0
|
| 221 | bad_oshrc:
|
| 222 | ## END
|
| 223 |
|
| 224 |
|
| 225 | #### PROMPT_COMMAND can see $?, like bash
|
| 226 |
|
| 227 | # bug fix #853
|
| 228 |
|
| 229 | export PS1='' # OSH prints prompt to stdout
|
| 230 |
|
| 231 | case $SH in
|
| 232 | *bash|*osh)
|
| 233 | $SH --rcfile /dev/null -i << 'EOF'
|
| 234 | myfunc() { echo last_status=$?; }
|
| 235 | PROMPT_COMMAND='myfunc'
|
| 236 | ( exit 42 )
|
| 237 | ( exit 43 )
|
| 238 | echo ok
|
| 239 | EOF
|
| 240 | ;;
|
| 241 | esac
|
| 242 |
|
| 243 | # Paper over difference with OSH
|
| 244 | case $SH in *bash) echo '^D';; esac
|
| 245 | ## STDOUT:
|
| 246 | last_status=0
|
| 247 | last_status=42
|
| 248 | last_status=43
|
| 249 | ok
|
| 250 | last_status=0
|
| 251 | ^D
|
| 252 | ## END
|
| 253 |
|
| 254 | #### PROMPT_COMMAND that writes to BASH_REMATCH
|
| 255 | export PS1=''
|
| 256 |
|
| 257 | case $SH in
|
| 258 | *bash|*osh)
|
| 259 | $SH --rcfile /dev/null -i << 'EOF'
|
| 260 | PROMPT_COMMAND='[[ clobber =~ (.)(.)(.) ]]; echo ---'
|
| 261 | echo one
|
| 262 | [[ bar =~ (.)(.)(.) ]]
|
| 263 | echo ${BASH_REMATCH[@]}
|
| 264 | EOF
|
| 265 | ;;
|
| 266 | esac
|
| 267 |
|
| 268 | # Paper over difference with OSH
|
| 269 | case $SH in *bash) echo '^D';; esac
|
| 270 |
|
| 271 | ## STDOUT:
|
| 272 | ---
|
| 273 | one
|
| 274 | ---
|
| 275 | ---
|
| 276 | bar b a r
|
| 277 | ---
|
| 278 | ^D
|
| 279 | ## END
|
| 280 | ## OK bash STDOUT:
|
| 281 | ---
|
| 282 | one
|
| 283 | ---
|
| 284 | ---
|
| 285 | clo c l o
|
| 286 | ---
|
| 287 | ^D
|
| 288 | ## END
|
| 289 |
|
| 290 |
|
| 291 | #### NO ASSERTIONS: Are startup files sourced before or after job control?
|
| 292 |
|
| 293 | cat >myrc <<'EOF'
|
| 294 |
|
| 295 | # from test/process-table-portable.sh
|
| 296 | PS_COLS='pid,ppid,pgid,sid,tpgid,comm'
|
| 297 |
|
| 298 | show-shell-state() {
|
| 299 | local prefix=$1
|
| 300 |
|
| 301 | echo -n "$prefix: "
|
| 302 |
|
| 303 | echo "pid = $$"
|
| 304 |
|
| 305 | # Hm TPGID has changed in both OSH and bash
|
| 306 | # I guess that's because because ps itself becomes the leader of the process
|
| 307 | # group
|
| 308 |
|
| 309 | ps -o $PS_COLS $$
|
| 310 | }
|
| 311 |
|
| 312 | show-shell-state myrc
|
| 313 |
|
| 314 |
|
| 315 | EOF
|
| 316 |
|
| 317 | $SH --rcfile myrc -i -c 'show-shell-state main'
|
| 318 |
|
| 319 | ## status: 0
|
| 320 |
|
| 321 | # No assertions
|
| 322 | # TODO: spec test framework should be expanded to properly support these
|
| 323 | # comparisons.
|
| 324 | # The --details flag is useful
|
| 325 |
|
| 326 |
|
| 327 | #### HISTFILE is written in interactive shell
|
| 328 |
|
| 329 | rm -f myhist
|
| 330 | export HISTFILE=myhist
|
| 331 | echo 'echo hist1; echo hist2' | $SH --norc -i
|
| 332 |
|
| 333 | if test -n "$BASH_VERSION"; then
|
| 334 | echo '^D' # match OSH for now
|
| 335 | fi
|
| 336 |
|
| 337 | cat myhist
|
| 338 | # cat ~/.config/oil/history_osh
|
| 339 |
|
| 340 | ## STDOUT:
|
| 341 | hist1
|
| 342 | hist2
|
| 343 | ^D
|
| 344 | echo hist1; echo hist2
|
| 345 | ## END
|
| 346 |
|
| 347 |
|
| 348 | #### HISTFILE default value
|
| 349 |
|
| 350 | # it ends with _history
|
| 351 | $SH --norc -i -c 'echo HISTFILE=$HISTFILE' | egrep -q '_history$'
|
| 352 | echo status=$?
|
| 353 |
|
| 354 | ## STDOUT:
|
| 355 | status=0
|
| 356 | ## END
|
| 357 |
|
| 358 | #### HISTFILE=my-history loads history from that file, and writes back to it
|
| 359 |
|
| 360 | echo 'echo 1' > my-history
|
| 361 |
|
| 362 | # paper over OSH difference by deleting the ^D line
|
| 363 | echo 'echo 2
|
| 364 | history' | HISTFILE=my-history $SH --rcfile /dev/null -i | sed '/\^D/d'
|
| 365 |
|
| 366 | echo
|
| 367 | echo '-- after shell exit --'
|
| 368 | cat my-history
|
| 369 |
|
| 370 | ## STDOUT:
|
| 371 | 2
|
| 372 | 1 echo 1
|
| 373 | 2 echo 2
|
| 374 | 3 history
|
| 375 |
|
| 376 | -- after shell exit --
|
| 377 | echo 1
|
| 378 | echo 2
|
| 379 | history
|
| 380 | ## END
|
| 381 |
|
| 382 | #### HISTFILE=my-history with history -a
|
| 383 |
|
| 384 | echo 'echo 1' > my-history
|
| 385 |
|
| 386 | # paper over OSH difference by deleting the ^D line
|
| 387 | echo 'history -a
|
| 388 | echo 2' | HISTFILE=my-history $SH --rcfile /dev/null -i | sed '/\^D/d'
|
| 389 |
|
| 390 | echo
|
| 391 | echo '-- after shell exit --'
|
| 392 | cat my-history
|
| 393 |
|
| 394 | ## STDOUT:
|
| 395 | 2
|
| 396 |
|
| 397 | -- after shell exit --
|
| 398 | echo 1
|
| 399 | history -a
|
| 400 | echo 2
|
| 401 | ## END
|