Bug 1589997

Summary: bash pipefail breaks grep -q
Product: [Fedora] Fedora Reporter: Jacob Keller <jacob.e.keller>
Component: bashAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 28CC: admiller, kasal, kdudka, svashisht
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-06-11 21:40:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
simple shell script highlighting the grep failures none

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.