My code
#!/bin/bash
for (( c=0; c<=1127; c++ ))
do
id = 9694 + c
if (id < 10000); then
wget http://myurl.de/source/image/08_05_27_0${id}.jpg
else
wget http://myurl.de/source/image/08_05_27_${id}.jpg
fi
done
I only get
./get.sh: line 5: 10000: No such file or directory
--2009-05-06 11:20:36-- http://myurl.de/source/image/08_05_27_.jpg
without the number.
The corrected code:
#!/bin/bash
for (( c=0; c<=1127; c++ ))
do
id=$((9694+c))
if (id -lt 10000); then
wget http://myurl.de/source/image/08_05_27_0${id}.jpg
else
wget http://myurl.de/source/image/08_05_27_${id}.jpg
fi
done
And even better:
for i in $(seq 9694 10821) ; do
_U=`printf "http://myurl.de/source/image/08_05_27_%05d.jpg" $i`
wget $_U
done
In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Increment Bash Variable with += Operator Another common operator which can be used to increment a bash variable is the += operator. This operator is a short form for the sum operator. The first operand and the result variable name are the same and assigned with a single statement.
The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.
I'll opt for simpler solution
for i in $(seq 9694 10821) ; do
_U=`printf "http://myurl.de/source/image/08_05_27_%05d.jpg" $i`
wget $_U
done
You are making a couple of mistakes with bash syntax, especially when dealing with arithmetic expressions.
This should work:
#!/bin/bash
for (( c=0; c<=1127; c++ )); do
id=$((9694 + c))
if ((id < 10000)); then
wget http://myurl.de/source/image/08_05_27_0${id}.jpg
else
wget http://myurl.de/source/image/08_05_27_${id}.jpg
fi
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With