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