大神们,请教一个关于shell函数退出的问题

回复 收藏
下面是我shell脚本里面的两个函数,第二个函数会调用第一个函数,但是在第一个函数判断退出的时候,你只能退出你所在的那个函数,而不是退出整个shell,请问有什么办法可以让我在第一个函数判断退出的时候退出整个shell脚本吗?


check_return(){
if [ $? -ne 0 ]
    then
        echo "$1"
        exit 1
fi
}

nodes_status() {
CURRENT_STAT=$(cat $serverstatus|grep \"myState\" |awk '{print $3}'|awk -F ',' '{print $1}'|sed 's/ *$//g'|sed 's/^ *//g')
check_return "-0.9906"
...
}

nodes_status



2015-10-17 10:50 举报
已邀请:
0

zhangsan

赞同来自:

虽然不知道你为什么要这么退出,我写这个不知道对你有没有用
[root@bogon zhangsan]# cat testkillself
#!/bin/sh
#test kill self
#written by zhangchaoyue
#2015/20/21
echo hello

killself(){
        echo "this script PID is $$"
        read wait
        [ $1 -eq 1 ] && kill -9 $$ &>/dev/null || exit 1
}

main(){
        killself 1
#       echo $?
}
main

[root@bogon zhangsan]# ./testkillself
hello
this script PID is 4199

Killed
[root@bogon zhangsan]#
0

lyhabc

赞同来自:

非常复杂   

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: