如何使用bash冲洗管道

Use*_*er1 11 bash named-pipes

我有一个脚本写入命名管道,另一个脚本从管道读取.有时,在启动脚本时,我注意到管道的内容存在于上一次运行的脚本中.有没有办法在脚本开头清除管道?

mvd*_*vds 11

我想dd是你的朋友:

dd if=myfifo iflag=nonblock of=/dev/null
Run Code Online (Sandbox Code Playgroud)

strace表演

open("myfifo", O_RDONLY|O_NONBLOCK)
Run Code Online (Sandbox Code Playgroud)

实际上甚至没有阻止一个空的fifo.

  • 不是使用 bash 内置命令/功能的意义上,而是绝对是使用标准 unix 工具的 shell 脚本解决方案的意义上。 (2认同)