阅读在bash输入一个while循环中 [英] Read input in bash inside a while loop

查看:144
本文介绍了阅读在bash输入一个while循环中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,它是像下面,

I am having a bash script which is something like following,

cat filename | while read line
do
    read input;
    echo $input;
done

但这显然没有给我正确的输出,当我在它试图从文件的文件名,因为可能的I / O重定向的读while循环做阅读。

but this is clearly not giving me the right output as when I do read in the while loop it tries to read from the file filename because of the possible I/O redirection.

做同样的任何其他方式?

Any other way of doing the same?

推荐答案

从控制终端设备阅读:

read input </dev/tty

更多信息:<一href=\"http://compgroups.net/comp.unix.shell/Fixing-stdin-inside-a-redirected-loop\">http://compgroups.net/comp.unix.shell/Fixing-stdin-inside-a-redirected-loop

这篇关于阅读在bash输入一个while循环中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆