I have written the following script:
cat BaseReCall.sh
#!/bin/bash
#### Usage: < input > < ref > < (array of dbsnps) >
input=$1
ref=$2
Pickle=$3
echo "${Pickle[@]}"
### Assign variables
BaseReCall="gatk BaseRecalibrator \\
-I $input \\
-R $ref \\
-O recal_table "
dir=$(dirname $input)
log=${dir}/BaseReCall.out
string=()
## Store array values in string
for i in "${Pickle[@]}";do
site=$(echo " --known-sites $i")
string+=$site
done
printf "$BaseReCall${string[@]}\n" #>> $log
The idea is to allow me to enter multiple dbsnp values as Pickle by using an array. If I type into bash the array looks fine.
Pickle=(dbSnp gold_standard_indels)
printf "${Pickle[@]}\n"
dbSnp gold_standard_indels
When I input it into my function however I don't get the two dbsnps. Only the first one.
sh BaseRecall.sh input ref "${Pickle[@]}"
dbSnp
gatk BaseRecalibrator \
-I input \
-R ref \
-O recal_table --known-sites dbSnp
Just as a sanity check I tried running the loop outside of the script too.
string=()
## Store array values in string
for i in "${Pickle[@]}";do
> site=$(echo " --known-sites $i")
> string+=$site
> done
printf "$BaseReCall${string[@]}\n" #>> $log
gatk BaseRecalibrator -I -R -O recal_table --known-sites dbSnp --known-sites gold_standard_indels
and it returned what I wanted all along. Is this happening because it is being inputted as a positional parameter? Is there a way to allow me to input multiple values for this Pickle parameter?