Frage

My bash script is

zenity --question --text=Continue? && echo Continuing...

How can I make it so it would echo Stopping if the user selected no? i.e.:

zenity --question --text=Continue? && echo Continuing... !&& echo Stopping...
War es hilfreich?

Lösung

It's not really the opposite of &&, but something like this might do:

zenity --question --text=Continue? && echo Continuing... || echo Stopping...

Andere Tipps

It's the logical OR, ||:

zenity --question --text=Continue? || echo Continuing...

(So true && cmd, false || cmd and cmd all do the same thing.)

Use || to create an "OR list":

zenity --question --text=Continue? && echo Continuing... || echo Stopping...

See http://www.gnu.org/s/bash/manual/bash.html#Lists.

if zenity --question --text='Continue?'
then echo Continuing...
else echo Stopping...
fi

There may be a way to do it on a single line but I usually use the following which I find a bit more readable:

if zenity --question --text=Continue?
then
        echo Continuing...
else
        echo Stopping...
fi
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top