从文件重定向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.

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

公众号