如何超时Bash命令并计算发送到stdout的行数?

Noe*_*Yap 5 bash

我想做点什么,timeout 12s tail -f access.log | wc -l但我没有看到输出wc.能做到这一点需要做些什么?

anu*_*ava 5

使用--foreground选项timeout

timeout --foreground 12s tail -f access.log | wc -l
Run Code Online (Sandbox Code Playgroud)

根据man timeout

--foreground   when not running timeout directly from a shell prompt,
               allow COMMAND to read from the TTY and get TTY signals;
               in this mode, children of COMMAND will not be timed out
Run Code Online (Sandbox Code Playgroud)