Question

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...
Was it helpful?

Solution

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

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top