精通unix shell脚本编程中关于while循环的问题!
时间:2011-11-28
来源:互联网
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.
请帮忙举个例子,谢谢!
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.
请帮忙举个例子,谢谢!
作者: zhpsam109 发布时间: 2011-11-28
是不是ksh不支持?
用bash试试
用bash试试
作者: justkk 发布时间: 2011-11-28
或者这样
cat ./test1.sh | while read line
..
cat ./test1.sh | while read line
..
作者: justkk 发布时间: 2011-11-28
他说这种用法,就是要不用管道的:
Using Command Output in a Loop
The technique shown here is a nice little trick to execute a command and use the
command’s output in a loop without using a pipe:
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.
Using Command Output in a Loop
The technique shown here is a nice little trick to execute a command and use the
command’s output in a loop without using a pipe:
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.
作者: zhpsam109 发布时间: 2011-11-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28