jeudi 22 juillet 2021

Why does if statement remove the concatenated variable from the filename in bash script?

I am new to programming with bash script and have run into an issue that I unfortunately have not been able to find the answer to. I have written some code that is supposed to check whether a file exists in a directory or not. The filename is a string with an attached numeric variable. When I concatenate the variable and string using echo it returns the correct output. However upon applying to the if statement, the concatenated numeric variable ${z} is left out of the output.

for ((c=$total; c=$start; c++))
do

  echo "in loop $c";
  
  num=502;
  echo $num
  
  z=$(($num+$c));
  echo $z
  
 
  echo "CL100127346_L02_${z}_1.fq.gz"
  
  if [ -f "CL100127346_L02_${z}_1.fq.gz" ];
  then
    
    echo "CL100127346_L02_${z}_1.fq.gz" exists
  
  else

    echo "CL100127346_L02_${path}_1.fq.gz does not exist"
    continue

  fi
done

I am guessing this is most likely a syntax error, however I am unable to find the answer. I would greatly appreciate any help. Thank you very much.

Aucun commentaire:

Enregistrer un commentaire