+ -
当前位置:首页 → 问答吧 → 这个 read命令为什么没执行

这个 read命令为什么没执行

时间:2011-04-10

来源:互联网

#!/bin/bash
while read line
do
read -p "Is this word $line correct:[y|n]" answer
case $answer in
y)
continue;;
*)
read -p "please input the correct word:" string
sed 's/$string/$line/g' >>a.txt
esac
done<a.txt

从a.txt中每读出一行 就询问单词是否正确 回答为 y 就继续读取 否则输入正确单词 在a.txt中用正确的单词取代错误的单词
上面的脚本 在
read -p "Is this word $line correct:[y|n]" 执行时就有问题 提示Is this word $line correct:[y|n]语句没出来 请教为啥子

作者: 123freebird   发布时间: 2011-04-10

回复 123freebird


    try:
  1. #!/bin/bash
  2. for line in `cat file`
  3. do
  4. read -p "Is this word $line correct:[y|n]" answer
  5. case $answer in
  6. y)
  7. continue;;
  8. *)
  9. read -p "please input the correct word:" string
  10. sed 's/$string/$line/g' >>a.txt
  11. esac
  12. done
复制代码

作者: yinyuemi   发布时间: 2011-04-10

回复 yinyuemi


    谢谢
    但是 while不是也可以循环从文件 读取吗 我那种写法 为啥不对呢

作者: 123freebird   发布时间: 2011-04-10

do 与done之间的read后面加上 <&0 试试.

作者: 惟吾无为   发布时间: 2011-04-10

回复 123freebird


    http://bbs.chinaunix.net/thread-674903-1-1.html
最后一个

作者: yinyuemi   发布时间: 2011-04-10

回复 惟吾无为


    谢谢 加了<&0不行
    不过你给了思路 我换成</dev/tty就可以了
    难道 read -p中 这个read 它还认为是从a.txt中读取么  所以  read -p执行失败?

作者: 123freebird   发布时间: 2011-04-10