Exit bash script on error in loop
Nils Kassube
kassube at gmx.net
Thu Sep 12 19:02:57 UTC 2013
Johnny Rosenberg wrote:
> 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.
Why do you put the yad command in the background? Maybe that's the
reason why it doesn't work. Would it be a problem if the script stops
after the yad job exits? After all it seems like it should display the
error message for only 5 seconds.
> (yad is a dialogue, similar to zenity, or even a zenity fork, I think
> – yad=Yet Another Dialogue)
Why do you use yad and not zenity? A short test with zenity worked here.
Nils
More information about the ubuntu-users
mailing list