Shell 参数传递

#!/bin/bash

helpdoc(){
    cat << EOF
Description:

    This shellscript is used to run the pipeline to call snp using GATK4
    - Data merge: merge multi-BAM files coresponding to specified strain
    - Data pre-processing: Mark Duplicates + Base (Quality Score) Recalibration
    - Call variants per-sample
    - Filter Variants: hard-filtering

Usage:

    $0 -S <strain name> -R <bwa index> -k <know-site> -i <intervals list>

Option:

    -S  strain name, if exist character "/", place "/" with "_" (Required)
    -R  the path of bwa index (Required)
    -k  known-sites variants VCF file
    -i  intervals list file,must be sorted (Required)

EOF
}

#$# 代表所有参数的个数
#若无指定参数,输出h说明文档

if [ $# = 0 ]
then 
    helpdoc
    exit 1
fi  

while getopts "h:S:R:k:i:" opt
do
    case $opt in
        h)
            helpdoc
            exit 0
            ;;
        S)
            strain=$OPTARG
            if [[ $strain =~ / ]]
            then
                echo "Error in specifing strain name , if exist character \"/\", place \"/\" with \"_\""
                helpdoc
                exit 1
            fi
            ;;

        R)
            index=$OPTARG
            ;;
        k)
            vcf=$OPTARG
            if [ ! -f $vcf ]
            then
                echo "NO SUCH FILE: $vcf"
                helpdoc
                exit 1
            fi
            ;;
        i)
            intervals=$OPTARG
            if [ ! -f $intervals ]
            then 
                echo "NO SUCH FILE: $intervals"
                helpdoc
                exit 1
            fi  
                ;;
            ?)
                echo "Unknown option: $opt"
                helpdoc
                exit 1
                ;;
    esac
done

echo $strain
echo $index 
echo $vcf
echo $intervals

参考:
perl、shell、python输出参数文档

此条目发表在Linux分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud