Reputation: 5044
I have the following issue.
I'm putting a string into a variable , $var1
. This string will be a numeric type e.g. 118
.
I did the following command line to fill my variable:
var1=$(cat test.html | grep "<quote")
But when I'm putting the variable into the loop below ...
for page in {1..$var1} ; do
wget "http://www.hellomovie.co.uk/movies/decade-2000/year-2001/?page=$page";
done
The wget is getting me this ...
Saved in : «index.html@page={1..118}»
[ <=> ] 135 284 --.-K/s in 0,1s 2014-04-08 15:36:58 (1,07 MB/ - «index.html@page=**{1..118}**.2» saved[135284]`
As you can see, the variable was not taken into account.
I tried the following to make sure that $var1
was seen as a numeric variable , $(($var1))
but to no avail.
I tried expr
but to no avail as well.
Did I do something wrong? If yes, can you pintpoint me where?
Any insights will be welcomed.
Cheers.
Upvotes: 2
Views: 117
Reputation: 784928
You cannot use variable as in {1..$N}
.
Use BASH arithmetic construct i.e. ((...))
:
for ((page=1; page<=var1; page++)); do
Upvotes: 3
Reputation: 12806
Try this:
for(( page=1 ; page <= $var1 ; page++)); do
wget "http://www.hellomovie.co.uk/movies/decade-2000/year-2001/?page=$page";
done
You're problem wasn't in assigning the variable, but trying to use $var1
inside of the { .. }
construct.
Upvotes: 1