小编cod*_*ann的帖子

为什么我的布尔测试在bash中切换?

我有这个bash功能,检查我是否在互联网上.它有助于我需要if internet-connected在bash脚本中进行快速测试的时刻.

由于它在上个月非常有用,我试图复制它的设计,有一个简单的ubuntu测试器,测试操作系统是否是Ubuntu.然后这发生了......

test.sh

internet-connected(){
    wget -q --spider http://google.com
    if [ $? -eq 1 ]
    then
        echo 'internet is connected'
        return 1
    else
        echo 'internet is not connected'
        return 0
    fi
}

echo "testing internet-connected"

if internet-connected
then
    echo 'connected'
else
    echo 'not connected'
fi

check-for-ubuntu(){
    tester=$(lsb_release -i | grep -e "Ubuntu" -c)
    if [ $tester -eq 1 ]
    then
        echo 'ubuntu detected'
        return 1
    else
        echo 'ubuntu not detected'
        return 0
    fi
}

echo ""
echo "testing …
Run Code Online (Sandbox Code Playgroud)

linux bash shell ubuntu boolean-logic

2
推荐指数
1
解决办法
77
查看次数

标签 统计

bash ×1

boolean-logic ×1

linux ×1

shell ×1

ubuntu ×1