backyard/wat/set-e.sh
2022-06-07 07:13:13 +02:00

32 lines
715 B
Bash

#!/usr/bin/env sh
# run this shell script with one of these shells:
# zsh, bash, dash, or (busybox) ash.
set -e
# false # this exits the shell immediately.
# false || false # this exits as well.
false && true # wait, what?
! true # huh?
fun() {
false # this *should* cause, the shell to exit, right...?
[ "$1" = 0 ]
}
if fun 0; then echo wat 1; fi
if false; then echo nope; elif fun 0; then echo wat 2; fi
i=0
while fun $i; do i=1; done
until fun $i; do i=0; done
# ! fun 0 # this exits zsh, and only zsh.
# (! (! fun 0)) # this exits bash, and only bash.
fun 0 && echo wat 3 || echo nope
fun 1 && echo nope
fun 0 || echo nope
echo aborting...
fun 0 # let's get out of here.
echo at least that works.