This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bash script for checking multi variable in if and for loop

Hi all,

I would like to create a small script for a particular detection and reporting but I can't reach my goal in bash, as a starter in shell scripting it is hard. Please correct or suggest it.

for i in VAR1 VAR2 VAR3 VAR4 VAR5 VAR6
do
  if [ "$i" == "$varab" ] 
  then
    VAR1="Haploid"
    VAR2="Diploid"
    VAR3="Triploid"
    VAR4="Tetraploid"
    VAR5="Pentaploid"
    VAR6="Hexaploid"
      echo "$i is the result"
      break
  else
    echo "$i is not working"
  fi
done;

varab - can be anything from VAR1 to VAR6

In short, I need to find what is the variable among 6 and report it properly.

bash shell

1 answer

You need a single equal sign to do the comparison. Try it with if [ "$i" = "$varab" ]. In shell [ is the program that does the test. So you can learn more about it from its man page man [.

Log in to answer this question.