function 函数

2020-12-02  本文已影响0人  蓝山_d851

function可以在脚本中起到简化代码,调用方便的用处

function fname()  {
                程序段
}

函数设置一定要设置到脚本的最前面,因为程序是从上到下执行的。

#!/bin/bash
function printit(){
              echo "Your choice is $1"  #这个$1是函数内部的内置函数。依赖下面指令的下达
}

echo "This progarm will print your  selection !"
case  $1  in
"one")
        printit  1 #函数后面接参数
        ;;
"two")
       printit  2
        ;;
"three")
      printit   3
        ;;
*)
      echo  "Usage $0 {one|two|three}"
        ;;
esa

输入 上面的选项就会出现对应的输出 如输出

[root@k8s-node2 tmp]# ./show-fction.sh one
This progarm will print your  selection !
Your choice is 1

学习笔记

上一篇 下一篇

猜你喜欢

热点阅读