At that point the script ends because I have the set -e
at the start.
Isto é uma falsidade.
Script comum:
$ cat ./weeble
set -e
if wobble ; then echo wobbled. ; else echo did not wobble. ; fi
echo did not fall down.
type wobble || exec false
exec true
$
Você diz que sabe como testar um comando desconhecido.
Almquist shell como /bin/sh
:
$ /bin/sh ./weeble ; echo $?
./weeble: wobble: not found
did not wobble.
did not fall down.
wobble: not found
1
$ /bin/sh -e ./weeble ; echo $?
./weeble: wobble: not found
did not wobble.
did not fall down.
wobble: not found
1
$
Korn shell como /bin/sh
:
$ /bin/sh ./weeble ; echo $?
./weeble[2]: wobble: not found
did not wobble.
did not fall down.
wobble not found
1
$ /bin/sh -e ./weeble ; echo $?
./weeble[2]: wobble: not found
did not wobble.
did not fall down.
wobble not found
1
$
Shell Bourne Again como /bin/sh
:
$ /bin/exec -a /bin/sh /usr/local/bin/bash ./weeble ; echo $?
./weeble: line 2: wobble: command not found
did not wobble.
did not fall down.
./weeble: line 4: type: wobble: not found
1
$ /bin/exec -a /bin/sh /usr/local/bin/bash -e ./weeble ; echo $?
./weeble: line 2: wobble: command not found
did not wobble.
did not fall down.
./weeble: line 4: type: wobble: not found
1
$
Z shell como /bin/sh
:
$ /bin/exec -a /bin/sh /usr/local/bin/zsh ./weeble ; echo $?
./weeble:2: command not found: wobble
did not wobble.
did not fall down.
wobble not found
1
$ /bin/exec -a /bin/sh /usr/local/bin/zsh -e ./weeble ; echo $?
./weeble:2: command not found: wobble
did not wobble.
did not fall down.
wobble not found
1
$
Como sua pergunta pergunta como evitar algo que não acontece em primeiro lugar e assume uma falsidade como sua premissa e seu título, ela é incontestável.