Q:

error when underscore _ comes after $i during a loop command

I am trying to download some fastq files from ENA and would like to do a loop for my commands. 
for (( i = 36; i <= 43; i++ ))

do

wget ftp.sra.ebi.ac.uk/vol1/fastq/SRR705/006/SRR70591$i/SRR70591$i_1.fastq.gz ftp.sra.ebi.ac.uk/vol1/fastq/SRR705/006/SRR70591$i/SRR70591$i_2.fastq.gz

done

and the output was this 
--2018-08-19 22:37:14--  http://ftp.sra.ebi.ac.uk/vol1/fastq/SRR705/006/SRR7059137/SRR70591.fastq.gz
Resolving ftp.sra.ebi.ac.uk (ftp.sra.ebi.ac.uk)... 193.62.192.7
Connecting to ftp.sra.ebi.ac.uk (ftp.sra.ebi.ac.uk)|193.62.192.7|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-08-19 22:37:14 ERROR 404: Not Found.

Notably the error occured because
"37_1" is missing from the output SRR70591.fastq.gz. 
I've tried various iterations of the, and found out that the command does not work well if underscore"_" goes directly after "$i" command.
Do you guys have any insights into how I can change the command to make it work? 
Thanks guys

A:

The problem you are having is due to the variable 'i' being followed by an '_' which can be part of the variable name itself. This causes a failure to substitute for i where both $i_1 and $i_2 occur in your wget command.
While not tagged bash, the following basic shell principals apply. It boils down to a basic understanding of word, name and parameter (or variable) definitions and requirement. For example, a word is defined as:
word    A sequence of characters considered as a single unit by the shell. 
        Also known as a token.

When used as a name, it has the following definition:
name    A word consisting only of alphanumeric characters and underscores, 
        and beginning with an alphabetic character or an underscore. 
        Also referred to as an identifier.

(Note carefully how "an underscore"  is included in the definition of a name.)
Finally when the name is used as a variable or parameter, the following applies:
${parameter}
        The value of parameter is substituted. The braces are required 
        when parameter is a positional parameter with more than one digit, 
        or when parameter is followed by a character which is not to be 
        interpreted as part of its name... 

(Note above when "braces are required")
Putting the pieces together, your loop and wget command could be reformed as:
for (( i = 36; i <= 43; i++ ))
do
  wget \
  ftp.sra.ebi.ac.uk/vol1/fastq/SRR705/006/SRR70591$i/SRR70591${i}_1.fastq.gz \
  ftp.sra.ebi.ac.uk/vol1/fastq/SRR705/006/SRR70591$i/SRR70591${i}_2.fastq.gz
done

(note: if you are unsure whether braces are required -- add them -- they do not hurt)
Also as noted in the comment, when you are developing and testing your script, an easy way to verify your commands are formed as you intend is to simply test by echoing your commands as output first, e.g. just wrap your entire command in quotes and echo it, e.g.
for (( i = 36; i <= 43; i++ ))
do
  echo "wget ...your full command..."
done

You can then verify your commands are formed as intended before turning your script loose on the web.

