首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

精通unix shell脚本编程中关于while循环的有关问题

2012-07-28 
精通unix shell脚本编程中关于while循环的问题!while read LINEdoecho $LINEdone (command)I know th

精通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 风格

两个<中间有个空格

热点排行