Problem in for loop of shell scripting in solaris

Hi below is my script

for((i=0;i<=$TOTAL;i++))
do
echo "IP's created are $s1.$s2.$s3.$s4"
s4=`expr $s4 + 1`
done

where s1,2,3,4 are input varibles
below error occurs while running the script

syntax error at lin 11: '(' unexpected

Any idea

Regards
Revathi

which shell are you using ?

a space after 'for' and '('

/bin/sh

Below is entire script

echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
echo "Total is $TOTAL"
if [ $e4 -gt $s4 ];then
echo "Total number of IPs are $TOTAL"
for((i=0;i<=$TOTAL;i++))
do
#/sbin/ifconfig bge0:$s4 plumb
#/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4
echo "Interfaces created are bge0:$s4"
echo "IP's created are $s1.$s2.$s3.$s4"
s4=`expr $s4 + 1`
done
else
echo "Smaller"
fi

Did you try this ?

Should be

#! /bin/sh

Please use CODE tags, it makes viewing the code much easier

Ya I have tried it. The same problem persisted

Code is below

#!/bin/sh
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
echo "Total is $TOTAL"
if [ $e4 -gt $s4 ];then
echo "Total number of IPs are $TOTAL"
for ((i=0;i<=$TOTAL;i++))
do
#/sbin/ifconfig bge0:$s4 plumb
#/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4
echo "Interfaces created are bge0:$s4"
echo "IP's created are $s1.$s2.$s3.$s4"
s4=`expr $s4 + 1`
done
else
echo "Smaller"
fi

Result is

bash-3.00$ sh test.sh
Enter the start IP
1.1.1.2
Enter the End IP
1.1.1.5
Total is 3
test.sh: syntax error at line 12: `(' unexpected

surprising ! :confused:

Its working as expected !

sh-2.05b$ sh test.sh
Enter the start IP
127.0.0.1
Enter the End IP
127.0.0.3
Total is 2
Total number of IPs are 2
Interfaces created are bge0:1
IP's created are 127.0.0.1
Interfaces created are bge0:2
IP's created are 127.0.0.2
Interfaces created are bge0:3
IP's created are 127.0.0.3

Thanks for ur reply.........
I have solved it using "while" loop anyway "for" loop is not working for me
I m using Solaris-10
Below is my code

#!/bin/sh
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
if [ $e4 -gt $s4 ];then
i=0
while [ $i -le $TOTAL ]
do
/sbin/ifconfig bge0:$s4 plumb
/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4 up
echo "IP's created are $s1.$s2.$s3.$s4"
echo "s4 is $s4"
s4=`expr $s4 + 1`
i=`expr $i + 1`
done
else
echo "End Ip should be greater than Start IP"
fi

One problem in the above script is that the interface is created using above script, but the Ip is not getting created to the interfaces(i.e the problem is in the line /sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4 up ).
But when i executing as individual lines as

/sbin/ifconfig bge0:1 plumb
/sbin/ifconfig bge0:1 192.168.100.1 up
it is working fine...........

Any idea about it

Is your sh linked to bash in turn ?

Can you post the output of

ls -l `which sh`

The output is

bash-3.00$ ls -l `which sh`
lrwxrwxrwx 1 root root 13 Aug 4 2006 /bin/sh -> ../../sbin/sh

Below is the output of the virtual IPs created manually and through script

bge0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 192.168.100.1 netmask ffffff00 broadcast 192.168.100.255*bge0:2: bge0:2:flags=1000851<UP,POINTOPOINT,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 0.0.0.192 --> 0.0.0.2 netmask ff000000
bge0:3: flags=1002851<UP,POINTOPOINT,RUNNING,MULTICAST,UNNUMBERED,IPv4> mtu 1500 index 2
inet 0.0.0.192 --> 0.0.0.3 netmask ff000000

bge0:1 is created manually (192.168.100.1 is pingable)
where as bge0:2 and bge0:3 are created through scripting(192.168.100.2 and 3 are not reachable)
I am unable to debug it
Any idea

Thanks for your valuable reply.
I solved the problem.
The problem is

/sbin/ifconfig bge0:${s4} ${s1}.${s2}.${s3}.${s4} up

this line is executed as /sbin/ifconfig bge0:$1 192 168 100 1 up
The point is not recognised.
The correct form is below

/sbin/ifconfig bge0:$s4 $s1"."$s2"."$s3"."$s4 up

Thanks
Revathi