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++))

  echo "in loop $c";
  echo $num
  echo $z
  echo "CL100127346_L02_${z}_1.fq.gz"
  if [ -f "CL100127346_L02_${z}_1.fq.gz" ];
    echo "CL100127346_L02_${z}_1.fq.gz" exists

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


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.

Read more here: https://stackoverflow.com/questions/68491775/why-does-if-statement-remove-the-concatenated-variable-from-the-filename-in-bash

Content Attribution

This content was originally published by Hans Owen at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: