Integer expression expected

hi Guys,

when i run the below script its showing error "integer expression expected"

script pasted below:

#!/bin/sh

for i in {1..$2}
do

if [ $i -lt 10 ]
then
  scp server1:/root/file.2012-$1-0$i .
else
  scp server1:/root/file.2012-$1-$i .
fi

done

please help on this. i have tried lot ways.

thanks,
Ganga.

You cannot put a variable in a {n..m} construct. Try:

#!/bin/bash

for ((i=1; i<=$2; i++))
do
  scp "server1:/root/file.2012-$1-$(printf "%02d\n" "$i")"
done

Although this could be made more robust. Anything wrong with the input and your script will break. You could check the content of $1 and $2 before you enter the loop if you want to avoid that..

Hi Scrutinizer,

i am getting below error when i run the script.

i am using Red hat Linux.

this is the explanation of my script:

server1 containing below files
file.2012-05-01
file.2012-05-02
.
.
file.2012-05-09
file.2012-05-10
file.2012-05-11
.
.
.
now i plan to download passing the parameters such $1 and $2, $1 is month and $2 is date.
sometimes i want to download up to 1st 7days sometimes 1st 15days.
this is the requirement. if u didn't understand let me know.

thanks for reply

regards,
ganga39

Ganga, where is the error message?

oh sorry i forgot that
here it is

line 3: ((: i<=: syntax error: operand expected (error token is "=")

Please post what Operating System and version you are running.
Have you got the bash Shell?

Red Hat Enterprise Linux Server release 5.5 (Tikanga)
ya i got the bash shell

You need to pass 2 parameters to the script..

yes

i got the solution dear....