Exit bash script on error in loop
Johnny Rosenberg
gurus.knugum at gmail.com
Thu Sep 12 18:19:25 UTC 2013
I can't make exit work as I thought it would work…
#!/bin/bash
Title="Error"
ERROR="Something bad happened."
while [ something ]; do
if [[ something_bad ]]; then
yad --title "${Title}" \
--image=error \
--text "${ERROR}" \
--no-buttons \
--timeout 5 &
exit 1
fi
done
more_statements
# End of code
The problem is that even if something_bad happens, more_statements are
executed. The yad error messages is displayed as expected, though.
(yad is a dialogue, similar to zenity, or even a zenity fork, I think –
yad=Yet Another Dialogue)
So it seems like only the loop is exited when exit 1 is executed, not the
whole script. So how can I exit the whole script if something bad happens
inside a loop? I'd prefer a solution that doesn't make it necessary to
rewrite the script from scratch…
Regards
Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20130912/d6c1d55c/attachment.html>
More information about the ubuntu-users
mailing list