#!/bin/bash
log()
{
msg=$1
time=$(date "+%Y-%m-%d %H:%M:%S" )
echo "${time}|${msg}"
}
usage()
{
cat <<EOF
Usage:smallskill.sh [OPTION]...
Mandatory arguments to long options are mandatory for short options too.
-e,--examination Send examination(test) massages
-x,--exclude Exclude build folder,use ';' to seperate
EOF
}
#-o或--options选项后面接可接受的短选项,如ex:s::,表示可接受的短选项为-e -x -s,其中-e选项不接参数,-x选项后必须接参数,-s选项的参数为可选的
#-l或--long选项后面接可接受的长选项,用逗号分开,冒号的意义同短选项。
#-n选项后接选项解析错误时提示的脚本名字["std.sh: unknown option -- d"]
ARGS=$(getopt -a -o e:x:s: -l examination:,exclude:,srcdir: -n "smallskill.sh" -- "$@")
#如果参数不正确,打印提示信息
[[ $? -ne 0 ]] && usage && exit 1
echo ${ARGS}
#将规范化后的命令行参数分配至位置参数($1,$2,...)
eval set -- "${ARGS}"
while true
do
case "$1" in
-e|--examination)
export TEST_MSG="$2"
shift
log "this is a test message! ${TEST_MSG}"
;;
-x|--exclude)
excludedir="$2"
shift
;;
-s|--srcdir)
srcdir="$2"
shift
;;
--)
shift
break
;;
esac
shift
done