如果否定在bash脚本条件 [英] Negate if condition in bash script

查看:439
本文介绍了如果否定在bash脚本条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来bash和我被困在试图否定下面的命令:

I'm new to bash and I'm stuck at trying to negate the following command:

wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
        echo "Sorry you are Offline"
        exit 1

如果我连接到互联网,这if条件返回true。我希望它会发生周围的其他方式,但把的任何地方似乎并没有工作。

This if condition returns true if I'm connected to the internet. I want it to happen the other way around but putting ! anywhere doesn't seem to work.

推荐答案

您可以选择:

if [[ $? -ne 0 ]]; then       # -ne: not equal

if ! [[ $? -eq 0 ]]; then     # -eq: equal

if [[ ! $? -eq 0 ]]; then

这篇关于如果否定在bash脚本条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆