| 您的位置:首页 > 文档 > Shell > |
文章分类热门文章 |
while循环中使用read创建:2005-10-26 00:49:45 作者:Unlinux 来自: http://www.Unlinux.com 如下SHELL #!/bin/sh cat file | while read line do echo "press any key" read key done read key这条语句不起作用,到底怎么回事?file为一个文本文件 while read line do ehco "hello" done < file 下面引用由yjlucky在 2002/10/09 09:07pm 发表的内容: 如下SHELL #!/bin/sh cat file | while read line do ... read key 当然也是从file里读了. 在循环中用read可以用以下方法! for line in `cat file` do echo "press any key" read key done 不行吧,那样line的内容就是一个个单词而不是一行行了。 楼主的意思好象是读完一行,敲任意键再读下一行吧? line 的值时file全文不是一行。 程序的设计思路不是太好,若一定要这要作,也可以作到: cat file | while read line do echo $line (echo "press any key:c"; exec </dev/tty; read key) done 高! 麻烦exec </dev/tty是做什么的? 我想应该是定向下一步的操作(read key)从键盘读输入吧 binary 说得对。 当需要对键盘输入进行判断并处理时,如下的脚本更好一点: cat file | while read line do echo $line echo " :: Please input any key(s):c" str4read="" while true do chr4read=`dd if=/dev/tty bs=1 count=1 2>/dev/null` str4read=$str4read$chr4read if [ "$chr4read" = "" ] ;then break; fi done echo " :: |$str4read|" done 转载自:http://www.unlinux.com/doc/shell/20051026/228.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接 无相关信息 |