Hi, I'll try to explain my problem the best I can. I have a script that runs multiple bowtie2 alignments. The problem is that it continues running the next alignment even if the current one fails to run.
script.sh
#!/bin/bash
bowtie2 --threads 32 -x sp_idx -U reads1.fastq | samtools view -Sbu - | samtools sort -@16 -m 4G > 1_sorted.bam
bowtie2 --threads 32 -x sp_idx -U reads2.fastq | samtools view -Sbu - | samtools sort -@16 -m 4G > 2_sorted.bam
bowtie2 --threads 32 -x sp_idx -U reads3.fastq | samtools view -Sbu - | samtools sort -@16 -m 4G > 3_sorted.bam
bowtie2 --threads 32 -x sp_idx -U reads4.fastq | samtools view -Sbu - | samtools sort -@16 -m 4G > 4_sorted.bam
What I want is that if there's an error while running Bowtie2, the script stops running and not keep running to the end. What's happening is that if line 2 fails, the script continues with the alignment of sample 3 and then 4. So why doesn't it stop running if line 2 is errors out?
Thanks!
Perfect, thanks!!!!
I tried set -e in the past and that didn't work. :-)
Probably because one of the commands that are part of a pipe failed, but the rightmost command in that pipe succeeded so the overall command chain took on that
0
exit code instead of the non-zero code of the failing command.Well, I learned something new today. Thx
That's how it always goes with the shell. Just when we think we know something, it surprises us.