2020-07-01 解析bash shell脚本命令行参数
#!/bin/bash
# function
function blastn() {
blastn -db ... -query .... -out ... -outfmt ...
}
function description() {
echo "Name:"
echo "bashDemo written by Y.P.CHEN:email@.com, 2020-07-01, chengdu"
echo "Synopsis:"
echo "show how to parse command-line arguments in bash shell"
echo "Usage:"
echo "bashDemo [option] arg ..."
echo "Example command:"
echo "...."
}
function print_help() {
grep '^##' $0 | sed 's/##//'
exit 1
}
# print help and exit
if [[ $# -eq 0 ]]; then
print_help
fi
if [[ $1 == "-h" || $1 == "--help" || $1 == "-help" ]]; then
print_help
fi
# check input
if [[ $# -ne 6 && $# -ne 14 ]]; then
echo '**Error invalid parameters group'
echo '----------------------------------------------------'
print_help
fi
# parse command-line arguments
while getopts i:o:t: OPT; do
case $OPT in
i)
input=$OPTARG
;;
o)
output=$OPTARG
;;
t)
threads=$OPTARG
;;
?)
echo "unkonw argument"
exit 1
;;
esac
done
shift $((OPTIND - 1))
# main
# call function blastn
blastn
# check variable
if [[ $input && $output && $threads ]]; then
...
fi
# if the variables do not exists.
if [[ !$input & ]]; then
...
fi
本文标题:2020-07-01 解析bash shell脚本命令行参数
本文链接:https://www.haomeiwen.com/subject/onbcqktx.html
网友评论