精通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
[解决办法]
[解决办法]
[解决办法]
<< 这不是here 风格么
< 这才是read line < filename 风格
[解决办法]
[解决办法]