考虑:
true; run_backup=$?
if [[ $run_backup ]]; then
echo "The user wants to run the backup"
fi
...和...
false; run_backup=$?
if [[ $run_backup ]]; then
echo "The user wants to run the backup"
fi
The user wants to run the backup
是否发出run_backup
有 0(成功)或 1(错误)!
这里发生了什么?
(我真正的命令,而不是true
or false
,其形式为zenity --question --text "..."
).
[[ $run_backup ]]
不是布尔检查;仅当其参数为空字符串(0 或 1 都不是)时,它才会失败。
Since zenity
如果单击“确定”,则返回 0,您想要类似的内容
[[ $run_backup -eq 0 ]] && echo "The user wants to run the backup"
or
(( run_backup == 0 )) && echo "The user wants to run the backup"
or
# You need to negate the value because success(0)/failure(!=0) use
# the opposite convention of true(1)/false(0)
(( ! run_backup )) && echo "The user wants to run the backup"
基于这样的事实run_backup
是 a 的退出状态zenity
在原始问题中命令,最简单的事情就是简单地使用&&
结合zenity
并将您的功能合并为一个命令。
zenity --question --width=300 --text "..." && echo "The user wants to run the backup"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)