ls *.fastq | xargs -I ./bbmap.sh 

How to correctly enter the arguments of this shell script? There are two of them.

Single-handed, not batch it works ---

 ./bbmap.sh ref=ref.fa # creating index file from the input reference ./bbmap.sh in=SRR1163136.fastq out=mapped.sam # performing mapping/alignment and producing SAM output 
  • where does the second argument come from? - aleksandr barakin

3 answers 3

Use: getopts

Brief example:

 #!/bin/bash while getopts "abc" opt do case $opt in a) echo "Found option $opt";; b) echo "Found option $opt";; c) echo "Found option $opt";; esac done 

This uses a loop that runs getopts with a list of valid options - "abc". The found options are assigned to the $opt variable, which is processed in the case .

    If you need to get several parameters for one command, you can:

      #!/bin/bash parm=( $1 $2 $3 $4 ); echo "${parm[@]}" 

    the parm variable in this case is an array, you can take any parameter passed from the string.

      The -I requires an argument — a sequence of characters in the command that will be replaced with the file name from the standard input, one per line or via zero byte if the -0 key is specified. In this case, the script will be called as many times as these file names will be received. The whole team should look something like this:

       ls *.fastq | xargs -I 'FILE' ./bbmap.sh in=FILE out=mapped.sam 

      The word FILE can be used in script arguments several times, but the same file name will be substituted instead of it, and not the following.