首页 > 技术文章 > syntax error near unexpected token `then'

tian880820 2016-05-25 16:00 原文

#!/bin/bash
# Enable RPS (Receive Packet Steering)

rfc=32768
cc=$(grep -c processor /proc/cpuinfo)
rsfe=32768

#临时修改net.core.rps_sock_flow_entries的值
#sysctl -w net.core.rps_sock_flow_entries=$rsfe
#设置rps_sock_flow_entries的值

echo '32768' >/proc/sys/net/core/rps_sock_flow_entries

#查看有几个网卡放到fileRps里:/sys/class/net/eth0/queues/rx-0/rps_cpus

for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus);do
if [ $cc = "2" ]; then
echo 3 > $fileRps
elif [ $cc = "4" ]; then
echo f > $fileRps
else "Unknown"
fi
done

 

修改写的shell脚本程序,结果执行时出现“syntax error near unexpected token `then'”,看半天没看出原因,上网查了半天,终于搞明白了原因:if 与‘['之间没有空格导致的。另外,在执行时,我也发现 ‘=’两边必须也得加空格,否则也会出错,不是语法出错,而是不管赋给a的值是多少,程序都会得到if 后面的语句为假,从而得出wrong的情况。

推荐阅读