In the line > +tempfile=$(mktemp -t doas.XXXXXXXX || exit 1)
the "|| exit 1" doesn't actually do anything. In order to exit the script the or bit must occur outside the subshell created by the parenthesis. So tempfile=$(mktemp -t doas.XXXXXXXX) || exit 1 This will work with simple assignments though not with 'typeset'. Additionally, as Martin Schröder pointed out, all editor calls should use $EDITOR, but in case a user doesn't have that defined, use ${EDITOR:-vi}