函数之间传参

#!/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
posted @ 2018-05-11 15:15  Me-lihu  阅读(2)  评论(0编辑  收藏  举报