日期:2014-05-16  浏览次数:20761 次

精通unix shell脚本编程中关于while循环的问题!
while read LINE
do
echo "$LINE"
done < <(command)

I know this looks a bit odd. I got this trick from one of my co-workers, Brian Beers.
What we are doing here is input redirection from the bottom of the loop, after the
done loop terminator, specified by the done < notation. The < (command) notation
executes the command and points the command’s output into the bottom of the loop.
NOTE The space between<<in < <(command)is required!

我测试了一下,始终报错,如下:

#!/bin/ksh
while read line
do
echo $line

done< <(cat ./test1.sh)

test2.sh[2]: 0403-057 Syntax error at line 6 : `<' is not expected.


请帮忙举个例子,谢谢!

------解决方案--------------------
是不是ksh不支持?
用bash试试
------解决方案--------------------
或者这样
cat ./test1.sh | while read line
..
------解决方案--------------------
#!/bin/ksh
while read line
do
echo $line

done<test1.sh
------解决方案--------------------
探讨

#!/bin/ksh
while read line
do
echo $line

done<test1.sh

------解决方案--------------------
探讨

引用:
你到bash试试看。。。能做出来就贴出来吧

如果你做不出来,就继续问。

#cat test.sh
#!/bin/bash
while read LINE
do
echo "$LINE"
done < <(ls)

#./test.sh
a.txt
b.txt
test.sh

------解决方案--------------------
<< 这不是here 风格么

< 这才是read line < filename 风格
------解决方案--------------------
探讨
<< 这不是here 风格么

< 这才是read line < filename 风格

------解决方案--------------------
探讨

引用:
<< 这不是here 风格么

< 这才是read line < filename 风格

两个<中间有个空格