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.