4

我的 bash 脚本是

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

如果用户选择否,我怎样才能让它回显 Stopping?IE:

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

5 回答 5

7

这并不是真正的相反&&,但这样的事情可能会:

zenity --question --text=Continue? && echo Continuing... || echo Stopping...
于 2011-11-27T18:18:27.030 回答
3

这是逻辑或,||

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

(所以true && cmd,所有人false || cmdcmd做同样的事情。)

于 2011-11-27T18:17:49.980 回答
0

用于||创建“OR列表”:

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

请参阅http://www.gnu.org/s/bash/manual/bash.html#Lists

于 2011-11-27T18:18:11.557 回答
0
if zenity --question --text='Continue?'
then echo Continuing...
else echo Stopping...
fi
于 2011-11-27T18:19:09.080 回答
0

可能有一种方法可以在一行中完成,但我通常使用以下内容,我发现它更具可读性:

if zenity --question --text=Continue?
then
        echo Continuing...
else
        echo Stopping...
fi
于 2011-11-27T18:20:39.370 回答