Hi,

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection         -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g -ffile-prefix-map=/build/bash/src=/usr/src/debug/bash -flto=auto -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS -std=gnu17 uname output: Linux ******** 6.17.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 24 Nov 2025 15:21:09 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.3
Patch Level: 8
Release Status: release

Description:
To start, I'm not totally sure if this is a bug with bash or with wc, as wc is the only program I have noticed this behavior in, but this seems like a good place to start.

In some scripts, I like to be able to programmatically check that certain programs are present and have certain versions. This works pretty well, except for when I pipe the output from wc, it some times returns an error code. Maybe it's wc's fault for not behaving well when it's being piped, but somehow that seems less likely than bash doing something to make wc return an error.

The inconsistent behavior makes this seem like a race, perhaps, in the script below, head is trying to close the pipe before wc finishes writing to it, causing it to return the error. I can also get this to sometimes happen with sed, but I assume that head is faster than sed and can "win" the race more often. But the fact that it can happen with both suggests that it's more likely to be a problem with bash than with head or sed.

My versions of wc and head are both from GNU coreutils 9.9, and my version of sed is 4.9

Repeat-By:
set -o pipefail
wc --version | head -n 1 ; echo $? # returns 141 ~50% of the time
wc --version | sed '1q' ; echo $?  # returns 141 very rarely, but it does happen

Thanks,

-Kye

--
Kye E. Hunter
PGP: 6859 E2DE D598 49EA 9319  10CD DEF2 BA03 A6BE 3062
--

Attachment: OpenPGP_0xDEF2BA03A6BE3062.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to