0
点赞
收藏
分享

微信扫一扫

函数之间传参

桑二小姐 2024-10-15 阅读 10

#!/bin/bash
. /etc/init.d/functions
function name() {
    if [ -z $1 ];then
        echo "Usg:sh $0 [ip/domain]"
        return 1
    else
    ping -c 3 $1 >/dev/null
        if [ $? -eq 0 ];then
            echo "up"
        else
            echo "down"
            return 2
        fi
    fi
}
result=$(name $1)   #取函数的运行结果,以及向函数里传参
echo $?             #取函数的return值
if [ "$result" == "down" ];then
    /sbin/ifdown eth1 >/dev/null
    action "eth1 is down" /bin/true
elif [ "$result" == "up" ];then
    /sbin/ifup eth1 >/dev/null
    action "eth1 is up" /bin/true
else
    echo $result
fi



举报

相关推荐

0 条评论