This is because grep -q
exits immediately with a zero status as soon as a match is found. The zfs
command is still writing to the pipe, but there is no reader (because grep
has exited), so it is sent a SIGPIPE
signal from the kernel and it exits with a status of 141
.
Another common place where you see this behaviour is with head
. e.g.
$ seq 1 10000 | head -1
1
$ echo ${PIPESTATUS[@]}
141 0
In this case, head
read the first line and terminated which generated a SIGPIPE
signal and seq
exited with 141
.
See "The Infamous SIGPIPE Signal" from The Linux Programmer's Guide.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…