• 自定义函数
    • 函数用于 “包含” 重复使用的命令集合

    • 自定义函数

      function fname() {
      	命令
      }
      

      function 可以省略

    • 函数的执行

      • fname

        function cdls() { cd /var; ls; }
        cdls
        
    • 函数作用范围的变量

      • local 变量名: 限制作用域范围
      #!/bin/bash
      
      # functions
      
      checkpid() {
          local i
      
          for i in $*  
          do  
              [ -d "/proc/$i" ] && return 0
          done
      
          return 1
      }
      
    • 函数的参数

      • $1 $2 $3 .. $n
      cdls() {  cd $1;  ls; }
      
      cdls /tmp
      
    • 清除函数

      • unset fname
  • 系统脚本
    • 系统自建了函数库,可以在脚本中引用
      • /etc/init.d/functions
      • /etc/profile
      • /etc/bashrc
      • ~/.bashec
    • ~自建函数库
      • 使用 source 函数脚本文件 “导入” 函数