Re-run an application script when it crashes?
Solution 1:
Try this:
while true; do xterm && break; done
Applications have exit status codes so that if something exits fine it returns zero... And if something went wrong, it throws out another number. This allows people to hook in and find out the exact issue. This is what the other answer is doing.
&&
just checks that the previous command was a zero-status exit and if it was, breaks the loop. If it crashes, it'll throw out something other than 0 and the && ...
clause won't trigger; it'll simply loop back around and run xterm
.
Solution 2:
In the while
condition you can test whether exit status of xterm
was successful or not with something like this:
result=1
while [ $result -ne 0 ]; do
xterm
result=$?
done
$?
variable holds exit status of last executed command.