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...
It's not really the opposite of &&
, but something like this might do:
zenity --question --text=Continue? && echo Continuing... || echo Stopping...
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...
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