Skip to content

should shellcheck warn *potential* SIGPIPE? #3506

Description

@e-kwsm

For new checks and feature suggestions

Here's a snippet or screenshot that shows a potential problem:

#!/bin/bash
set -eo pipefail
seq 100000 | head
echo unreachable

Here's what shellcheck currently says:

nothing.

Here's what I wanted to see:

-:3:14: warning: This may send SIGPIPE and abort execution
OK commands
  • cat
  • cut
  • fold
  • grep without -q etc
  • od
  • paste
  • sha1sum etc
  • shuf
  • sort
  • tac
  • tail
  • tr
  • uniq
commands that may send SIGPIPE

Of course SIGPIPE is not sent when the grep patten does not match or piped data is small enough (< 1 MiB).

commands that may send SIGPIPE (unclear)
  • nawk—exit
  • sed—q

It is hard to check awk and sed because it depends on the script bodies (and awk implementation):

seq 100000 |
  awk -f scriptfile
# ^~ This may send SIGPIPE and abort execution, depending on the script

and eventually

seq 100000 |
  unknown-command
# ^~ ShellCheck does not know this command and cannot guarantee that SIGPIPE will not sent

# if ShellCheck knows that the command does not read stdin, SC2216 will be issued

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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