getopt-simple.sh

来自「BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版」· Shell 代码 · 共 45 行

SH
45
字号
#!/bin/bash# getopt-simple.sh# 作者: Chris Morgan# 已经经过授权, 可以使用在本书中.getopt_simple(){    echo "getopt_simple()"    echo "Parameters are '$*'"    until [ -z "$1" ]    do      echo "Processing parameter of: '$1'"      if [ ${1:0:1} = '/' ]      then          tmp=${1:1}               # 去掉开头的'/' . . .          parameter=${tmp%%=*}     # 提取参数名.          value=${tmp##*=}         # 提取参数值.          echo "Parameter: '$parameter', value: '$value'"          eval $parameter=$value      fi      shift    done}# 把所有选项传给函数getopt_simple().getopt_simple $*echo "test is '$test'"echo "test2 is '$test2'"exit 0---sh getopt_example.sh /test=value1 /test2=value2Parameters are '/test=value1 /test2=value2'Processing parameter of: '/test=value1'Parameter: 'test', value: 'value1'Processing parameter of: '/test2=value2'Parameter: 'test2', value: 'value2'test is 'value1'test2 is 'value2'

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?