如何在 bash 脚本中在单独的行中为每个标志添加注释?

Sam*_*mpa 2 bash command-line

我想编写尽可能自我记录的 bash 脚本。

我有一个想法,当我执行带有大量标志的软件时,我想将命令分成多行,并在每行末尾添加注释,说明标志的作用(来自手册页的信息),就像这样:

bwa aln \
-n $n \ # -n max #diff (integer) or missing prob under 0.02 err rate (float) [0.04]
-o $o \ # -o maximum number or fraction of gap opens [1]
-e $e \ # -e maximum number of gap extensions, -1 for disabling long gaps [-1]
-i $i \ # -i do not put an indel within integer bp towards the ends [5]
-d $d \ # -d maximum occurrences for extending a long deletion [10]
-l $l \ # -l seed length [32]
-k $k \ # -k maximum differences in the seed [2]
-m $m \ # -m maximum entries in the queue [2000000]
-t $t \ # -t number of threads [1]
-M $M \ # -M mismatch penalty [3]
-O $O \ # -O gap open penalty [11]
-E $E \ # -E gap extension penalty [4]
-R $R \ # -R stop searching when there are >integer equally best hits [30]
-q $q \ # -q quality threshold for read trimming down to 35bp [0]
-f $f \ # -f file to write output to instead of stdout
-B $B \ # -B length of barcode
-L $L \ # -L log-scaled gap penalty for long deletions
-N $N \ # -N non-iterative mode: search for all n-difference hits (slooow)
-I $I \ # -I the input is in the Illumina 1.3+ FASTQ-like format
-b $b \ # -b the input read file is in the BAM format
-0 $0 \ # -0 use single-end reads only (effective with -b)
-1 $1 \ # -1 use the 1st read in a pair (effective with -b)
-2 $2 \ # -2 use the 2nd read in a pair (effective with -b)
-Y $Y \ # -Y filter Casava-filtered sequences
-prefix $prefix \ # -prefix Prefix
-inputfile $inputfile \ # -inputfile Input file (FastQ format)
Run Code Online (Sandbox Code Playgroud)

问题是我在 \ 字符之后不能有任何东西(告诉 bash 命令在下一行继续),我也不能在行尾有“\”,因为它被视为的一部分评论。

有人知道这样做的方法或类似的方法吗?

Jos*_*a K 5

我建议在命令之前使用多行来注释代码。喜欢

 # this command uses multiple parameters
 # it requires 4 parameters and none are optional with no defaults
 # parameters used : 
 # -q              name of the file
 # -b              size to truncate
 # -n              new location
 # -r              recursive
Run Code Online (Sandbox Code Playgroud)