Skip to content

pipefail and grep -q wont get along well #665

Description

@redbaron

My colleague @james-masson found an interesting problem when set -o pipefail is combined with grep -q and the input to grep is produced in small chunks (like reasonably short line at a time). This combination leads to race condition when process producing input to grep may or may not receive SIGPIPE and therefore may or may not produce non 0 exit code.

#!/bin/bash

set -e
set -o pipefail

while true
do
ip route  | grep -q "." 
echo "done"
done

it would be awesome if shellcheck warned about it, because in general case combination of pipefail and grep -q can not produce consistent results

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions