【发布时间】:2015-12-06 18:07:34
【问题描述】:
使用此代码我收到此错误,并且我的功能不可用:
Erreur de syntaxe près du symbole inattendu «
function my_func{
while read Port
do
CHECK_HG=`raidcom get host_grp -port $Port -IH${CCI_INST} |grep -iw ${HOST}`
if [ ! -z "$CHECK_HG" ]; then
export HMO=`raidcom get host_grp -port $Port -IH${CCI_INST} | grep -i ${HOST} | awk -F " " '{print \$5}'`
if [ $HMO == "LINUX/IRIX" ]; then
HMO=`echo $HMO | awk -F "/" '{print \$1}'`
fi
#comment
NBPort=`expr $NBPort + 1`
#comment
PORT_HG=$PORT_HG"$Port;\n"
fi
done < <(echo -e "$TARGET_PORTS")
}
因此,当我更改循环时,我没有收到任何错误,但我会丢失变量中的所有数据以在主脚本中恢复。
function my_func{
echo -e "$TARGET_PORTS" | while read Port
do
CHECK_HG=`raidcom get host_grp -port $Port -IH${CCI_INST} |grep -iw ${HOST}`
if [ ! -z "$CHECK_HG" ]; then
export HMO=`raidcom get host_grp -port $Port -IH${CCI_INST} | grep -i ${HOST} | awk -F " " '{print \$5}'`
if [ $HMO == "LINUX/IRIX" ]; then
HMO=`echo $HMO | awk -F "/" '{print \$1}'`
fi
#comment
NBPort=`expr $NBPort + 1`
#Comment
PORT_HG=$PORT_HG"$Port;\n"
fi
done
}
有什么想法吗? 非常感谢。
【问题讨论】:
-
也许尝试在 while 循环结束时删除一个 '
-
不...同样的错误:完成
-
您正在使用
bash以外的 shell 执行脚本,并且该 shell 不理解进程替换。 -
更简单:
for Port in $TARGET_PORTS;
标签: bash loops while-loop