shell 参数使用
关于shell中使用参数的两个例子:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 while getopts :s:o:ghe OPTION 2 do 3 case $OPTION in 4 s) 5 snp=$OPTARG 6 echo "snp=$snp" 7 ;; 8 o) 9 outdir=$OPTARG 10 echo "outdir=$outdir" 11 ;; 12 g) 13 if=1 14 echo "we will get hg18" 15 ;; 16 h) 17 chunhe=1 18 echo "use hom" 19 ;; 20 e) 21 zahe=1 22 echo "use het" 23 ;; 24 ?) 25 echo "usage:$0 -s \$snp_file -o \$outdir (-g:if u need hg18) (-h:out_for_hom) (-e:out_for_het)" 26 ;; 27 esac 28 done 29 30 shift $((OPTIND-1)) 31 echo "other = $@"
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 set -- `getopt s:o:ghe $*` 2 3 while [ -n $1 ] 4 do 5 case $1 in 6 -s) 7 snp=$2 8 echo "snp=$snp" 9 shift 10 ;; 11 -o) 12 outdir=$2 13 echo "outdir=$outdir" 14 shift 15 ;; 16 -g) 17 if=1 18 echo "we will get hg18" 19 ;; 20 -h) 21 chunhe=1 22 echo "use hom" 23 ;; 24 -e) 25 zahe=1 26 echo "use het" 27 ;; 28 --) 29 shift 30 break 31 ;; 32 *) 33 echo "$1 is not a option!" 34 echo "usage:$0 -s \$snp_file -o \$outdir (-g:if u need hg18) (-h:out_for_hom) (-e:out_for_het)" 35 ;; 36 esac 37 shift 38 done 39 40 echo "other = $@"