我有这个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 …Run Code Online (Sandbox Code Playgroud)