This is a test version of Biostars. For the public version, visit https://www.biostars.org.
comparing 2 intergers inside an if statement in bash

Hi there Can anyone hlep me please?

I am using a bash script to look at fasta files output by another script that makes a new consensus sequence from Illumina sequencing data.

I have 2 potential correct expected outcomes, either a new consensus that is 1 fasta sequence, or 8 fasta sequences. If it is anything else I just want to exit the scipt.

So I'm intending to count up the number of > in my fasta file, if the outcome is 1 or 8 then carry on, if its any other number exit.

I'm just not able to make my if statement do what i want, maybe it's just not possible. I've started along these lines

numseqs=$(grep -o ">" "$infile" | wc -l)

    if [ "$numseqs" -ne 1 OR 8 ] ; then
echo Number of sequences is NOT 1 or 8
exit
else
echo you have 1 or 8 sequences in your fasta file

carry on and run more commands
fi

After some googling Ive tried -ne 1 OR 8, -ne 1 | 8, -ne 1 || 8, -ne 1 && 8, but i'm pretty lost. Any help please?

Thank you James

bash if variable

Try something like:

if [ "$numseqs" -ne 1 ] || [ "$numseqs" -ne 8 ] ; then
 numseqs=2 && if [ "$numseqs" -ne 1 ] && [ "$numseqs" -ne 8 ] ; then echo "Number of sequences is NOT 1 or 8" ; fi

Hello James!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics. just bash

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Hello Pierre

Sorry, you are right. I thought of this website because I'm using bash for analysis of illumina sequencing data but this really is just a bash question.

Also, thank you so much for sorting out my problem.

Many thanks James

0 answers

No answers yet.

Log in to answer this question.