cod*_*ann 2 linux bash shell ubuntu boolean-logic
我有这个bash功能,检查我是否在互联网上.它有助于我需要if internet-connected
在bash脚本中进行快速测试的时刻.
由于它在上个月非常有用,我试图复制它的设计,有一个简单的ubuntu测试器,测试操作系统是否是Ubuntu.然后这发生了......
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 check-for-ubuntu"
if check-for-ubuntu
then
echo 'this is ubuntu'
else
echo 'this is not ubuntu'
fi
Run Code Online (Sandbox Code Playgroud)
testing internet-connected
internet is not connected
connected
testing check-for-ubuntu
ubuntu detected
this is not ubuntu
[Finished in 0.9s]
Run Code Online (Sandbox Code Playgroud)
为什么逻辑在这两个函数中似乎是倒退的?
你们回答的确很好,谢谢.