微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有这个:

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.

因此,因为您从文件中读取行而不是从终端提示中读取未显示的行.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐