简体   繁体   English

busybox网络配置脚本错误

[英]busybox network configuration script error

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 这是我的ipconf文件

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]} . 我的脚本在ifconfig eth0 ${ipValues[0]} netmask ${ipValues[1]} Is this array assignment is correct or busybox scripts needs different approach? 这个数组分配是正确的还是busybox脚本需要不同的方法?

You're right, busybox doesn't support the array syntax in your script. 没错,busybox在脚本中不支持数组语法。

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}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM