Question

Hello I have the script in the start up but I don't get why it is showing error on execution

#!/bin/sh

# Starting the network interface

PATH="/sbin:/bin:/usr/bin:/usr/sbin"


FILENAME="/etc/ipconf"
count=0

while read LINE
do
  ipValues[count]=$(echo $LINE |  awk -F'=' '{print $2}')
  count=`expr $count + 1`
done < $FILENAME

echo "Setting up IP Address"
ifconfig eth0 up
ifconfig eth0 ${ipValues[0]} netmask ${ipValues[1]}
echo "IP :: ${ipValues[0]} SUBNET MASK :: ${ipValues[1]}"
route add default gw ${ipValues[2]}
echo "Default Gateway :: ${ipValues[2]}"

echo "Network configured properly"

exit 0

Here is my ipconf file

IPADDRESS=192.168.1.13
SUBNETMASK=255.255.255.0
GATEWAY=192.168.1.220

And here is my scripts error

ipValues[count]=192.168.1.13 Not found
ipValues[count]=255.255.255.0 Not found
ipValues[count]=192.168.1.220 Not found
Setting up IP Address
Line 20 syntax error: Bad substitution

My script is braking in line ifconfig eth0 ${ipValues[0]} netmask ${ipValues[1]}. Is this array assignment is correct or busybox scripts needs different approach?

Was it helpful?

Solution

You're right, busybox doesn't support the array syntax in your script.

In order to set the values, you might use

eval ipValues$count=$(echo $LINE |  awk -F'=' '{print $2}')

and to read the variables

ifconfig eth0 ${ipValues0} netmask ${ipValues1}
echo "IP :: ${ipValues0} SUBNET MASK :: ${ipValues1}"
route add default gw ${ipValues2}
echo "Default Gateway :: ${ipValues2}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top