shell脚本:ambiguous redirect



 nlines=6
index=0
iplist=
while read line
do
    index=$[ ${index}+1 ]
    iplist[$index]="$line"
done < `sed -n "5,${nlines}p" "cloudfs_deploy.conf"`
echo ${iplist[@]}

运行这段脚本之后,总是在sed那行报ambiguous redirect错误
conf文件存在,有6行,我单独运行
nlines=6 ; sed -n "5,${nlines}p" "cloudfs_deploy.conf"
是没有错误的
求教这是什么原因?

Linux sed shell bash

Ppeng 9 years, 7 months ago

因为第六行你使用了奇怪的语法。显然你想要的是:


 bash


 nlines=6
index=0
iplist=
sed -n "5,${nlines}p" "cloudfs_deploy.conf" | while read line; do
    index=$[ ${index}+1 ]
    iplist[$index]="$line"
done
echo ${iplist[@]}

从来不起名 answered 9 years, 7 months ago

Your Answer