DEV Community

Roy
Roy

Posted on

1

bash 函数 return 1 是表示执行失败

#!/bin/bash

function check_k8s() {
    port_6443=`netstat -nlt | grep -w 6443 | wc -l`
    if  [ $port_6443 = 0 ]; then
      #不存在k8s
      return 0
    else
      #存在k8s
      return 1
    fi
}

function return0 (){
  return 0
}

function return1 (){
  return 1
}

if check_k8s; then
   echo 1
else
   echo 0
fi
Enter fullscreen mode Exit fullscreen mode

在if 语句的条件中调用 return 非0的函数,执行失败分支

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay