'exit after echo if command fails _always_ exiting
I have a bash script setup where I eval a variable called snake and exit if there was an error. Even though there is no error upon executing the snake command, the aws s3 commands below are not executed.
if I removed || echo "ERROR OCCURED, LOOK ABOVE. EXITING" ; exit 1, then the aws commands will execute.
I know there isn't an error upon eval $snake because echo "ERROR OCCURED, LOOK ABOVE. EXITING" isn't returned to standard out (it only is when there is actually an error).
I need the aws commands to execute after successfully running eval $snake, but I'm unsure of how to do this.
s3='ebio/'
# do not edit contents below unless needed
snake="snakemake --default-remote-provider S3 --default-remote-prefix '$s3' --use-conda --cores 32 --rerun-incomplete --printshellcmds"
read -p "Rewrite over samples.tsv, peak_norm.tsv, and treated_vs_untreated.tsv files? (y/n)" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
# exit if snake fails
eval $snake || echo "ERROR OCCURED, LOOK ABOVE. EXITING" ; exit 1
# remove temp files
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*tmp"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*sam.parsed"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*sam.parsed.done"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*.sam.tmp.combined_w_uniquemap.rmDup.sam"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*.sam.tmp.combined_w_uniquemap.prermDup.sam"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*.adapterTrim.round2.rmRep.bam.tmp"
aws s3 rm --recursive s3://"$s3"rep_element_pipeline --exclude "*" --include "*.fastq.gz.mapped_vs_bt2_hg38.sam"
aws s3 rm --recursive s3://"$s3"data_analysis --exclude "*" --include "*.saturations_reads.txt"
fi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
