linux - 当 i/p 从文件重定向时读取不提示

标签 linux bash

我有这个:

while read -r line; do echo "hello $line"; read -p "Press any key" -n 1; done < file

hello This is line 1
hello his is line 2
hello his is line 3
hello his is line 4
hello his is line 5
hello his is line 6
hello his is line 7

为什么我没有看到“按任意键”的提示?

最佳答案

引自man bash:

-p prompt
   Display prompt on standard error, without a trailing new
   line, before attempting to read any input. The prompt is
   displayed only if input is coming from a terminal.

因此,因为您从文件中读取行而不是从终端提示中读取行,所以不会显示。

关于linux - 当 i/p 从文件重定向时读取不提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6398908/

相关文章:

linux - 最有效的压缩超大数据集

linux - exec 3<>/dev/tcp/anyaddress.com/80 在 ash 中的等价物

linux - 如何将 bash 脚本的输出重定向到动态屏幕?

bash - 带有/空格+ ssh的变量

linux - 是否可以使 bash shell 脚本与另一个命令行程序交互?

linux - 为内核设置构建选项

linux - PhantomJS:中文字符在生产服务器上显示为 block

php - 我的 .htaccess 文件有什么问题,以便它可以在 linux 上运行?

linux - FATA[0000] 获取http :///var/run/docker. sock/v1.17/version : dial unix/var/run/docker. sock

mysql - 错误 : 'Can' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing/var/run/mysqld/mysqld. socks