暂停循环直到按下键

Ste*_*ell 7 bash for-loop

如何运行在每次迭代后暂停直到按下某个键的 for 循环?例如,如果我想打印文件 1、文件 2、文件 3 的行号,但只在按下一个键后继续:

for f in dir/file? ; do wc -l $f ; pause until key is pressed ; done
Run Code Online (Sandbox Code Playgroud)

抱歉,如果这是微不足道的,我是编码新手。

Ini*_*ian 7

使用read命令等待-n1用户输入的单个字符( )

read -p "Press key to continue.. " -n1 -s
Run Code Online (Sandbox Code Playgroud)

man read页面中使用的选项,

-n nchars return after reading NCHARS characters rather than waiting 
          for a newline, but honor a delimiter if fewer than NCHARS
          characters are read before the delimiter

-s      do not echo input coming from a terminal

-p      prompt output the string PROMPT without a trailing newline before
        attempting to read
Run Code Online (Sandbox Code Playgroud)