getopts用于解析命令行参数,是“shell builtin commands are inherited from the Bourne Shell”
参考:
http://www.gnu.org/s/bash/manual/html_node/Bourne-Shell-Builtins.html#Bourne-Shell-Builtins
代码:
#!/bin/bash
# Example: args parse
usage() {
local prog="`basename $1`"
echo "Usage: $prog -n name1 [name2...] [-c count] [-D DestDir]"
echo " $prog -h for help."
exit 1
}
showhelp() {
echo "Usage: `basename $1`: -n name1 [name2...] [-c count] [-D OutputDir]"
echo " -n target name (\"None\" for no tag)"
echo " -c count for each name (\"None\"=1)"
echo " -D output directory"
echo " -h show this help"
exit 1
}
name&