jeudi 6 août 2020

Why If statement raises [[: not found error only when run indipendently?

I am creating a script using bash. However during the IF statement it raises this error: [[: not found. I read this topic in other posts but it seems that my predecessors were writing bad their code (eg forgetting spaces or else). My question is a little bit different because THE SAME code if run within other parts does not work but if I lauch it totally alone it correctly works. Why does this happens? I premit that the variable used is the only one along the whole code.

echo "Digit how many codon positions do you want to use for your partition. [2-3]"
read codonpos
echo $codonpos
[[ "$codonpos" = "2" ]] && echo im here

I also tried:

echo "Digit how many codon positions do you want to use for your partition. [2-3]"
read codonpos
echo $codonpos
if [[ "$codonpos" = "2" ]] 
     then
     echo im here

fi

I repeat you that if lauch indipendently it works but, if this is embedded in a larger code it doesn't.

Thank you very much for your help

Aucun commentaire:

Enregistrer un commentaire