Bug 1589997 - bash pipefail breaks grep -q
Summary: bash pipefail breaks grep -q
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: 28
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Siteshwar Vashisht
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-06-11 19:40 UTC by Jacob Keller
Modified: 2018-06-11 21:42 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2018-06-11 21:40:15 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
simple shell script highlighting the grep failures (2.20 KB, application/x-shellscript)
2018-06-11 19:40 UTC, Jacob Keller
no flags Details

Description Jacob Keller 2018-06-11 19:40:01 UTC
Created attachment 1450179 [details]
simple shell script highlighting the grep failures

Description of problem:

bash pipefail causes "grep -q" to return different results from "grep"


Version-Release number of selected component (if applicable):

GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu)


How reproducible:

always

Steps to Reproduce:
set -o pipefail; if gcc --help=warnings | awk '{print $1}' | grep -F -q -- "-Wmisleading-indentation" ; then echo yay; fi

Actual results:
no output

Expected results:
output of "yay"

Additional info:

This doesn't seem to work for all grep invocations, for example -Wvla seems to work, but -Wmisleading-indentation does not.

Removing the pipefail fixes this, as does removing the -q option of grep.

I've added an attachment which shows each of these issues.

I tried running the script through strace, but wasn't able to find anything obviously wrong.

Comment 1 Jacob Keller 2018-06-11 19:40:45 UTC
Further testing seems to indicate this is also broken in F27.

Comment 2 Siteshwar Vashisht 2018-06-11 21:40:15 UTC
This is not a bug. When grep is invoked with -q option, it closes input end of the pipe as soon as it hits first occurence of "-Wmisleading-indentation". That may cause awk to exit with non-zero status as the reading end of the pipe has been closed. You can workaround it by redirecting grep output to /dev/null and removing -q option.

Comment 3 Jacob Keller 2018-06-11 21:42:54 UTC
Ahhh, yea that makes sense.


Note You need to log in before you can comment on or make changes to this bug.