I am submitting a series of batch jobs in a bash script.
The batch script (script.sh) is as follows:
samtools merge $1 $2
$1 is the output and it is only one single file. So, it is no problem.
$2 is the input but it is not only one file, it is several files and it is different in every directory. The bash script is as follows:
for i in directory1 directory2
do
cd $i
d=$(echo *specific_prefix.txt)
echo $d
sbatch script.sh ${i}.output $d
cd ..
done
Running as above, the batch script only takes the first element of $d as its variable. Is there a way for a bash variable ($2) to take varying number of variables, for example for it to be a list whose length can be determined in another variable?
Edit:
I have the sbatch job script (merge.sh) as:
#!/bin/bash -l
arg1="$1"
shift 1
arg2=("$@")
samtools merge arg1 arg2
And I run it using a bash script:
#!/bin/bash -l
for i in directory
do
cd $i
d=$(echo *RG.sort.dedup.bam)
sbatch merge.sh ${i}.output $d
cd ..
done
The error is: samtools merge: fail to open "arg2": No such file or directory
What could be the error in the script? Thanks!
samtools. Also you need to usesamtools merge "$arg1" "${arg2[@]}. Also I don't know what issbatchbeforemerge.shsamtoolsis just the name of a programme in bioinformatics andsbatchis a command we use to submit batch jobs into our computer cluster. Thank you again!