shell——替换

1. 高级变量替换

2. getopts

getopts 是bash 内建命令,语法为

getopts optstring name [args]
#!/bin/bash

function help()
{
        echo "Usge getopts.sh [opts]"
        echo "options:"
        echo "                  -f file"
        echo "                  -e edit"
        echo "                  -p"
}

if [ $# -eq 0 ]; then
        help
        exit
fi

# 关闭诊断信息
OPTERR=0
while getopts f:e:p: OPTION
do
        case "$OPTION" in
                f)
                        echo "file : $OPTARG"
                        ;;
                e)
                        echo "edit : $OPTARG"
                        ;;
                p)
                        echo "PAGE : $OPTARG"
                        ;;
                \?)
                        help
                        ;;
        esac
done

posted on 2022-03-25 10:04  开心种树  阅读(107)  评论(0编辑  收藏  举报