Skip to content

Recommend set -eufo pipefail and discourage POSIX traps #3288

@mcandre

Description

@mcandre

For new checks and feature suggestions

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

seach-java:

#!/bin/sh
trap ./clean ERR EXIT SIGINT

(false)

ls test/*

find "$JAVA_HOME" -type f -name -print0 |
    xargs -0 echo
$ mkdir -p test/fixtures
$ unset JAVA_HOME
$ ./search-java
...

Here's what shellcheck currently says:

Nothing

Here's what I wanted to see:

  • Prefer function traps to list traps for safety
  • Enable set -e to safeguard against system corruption
  • Enable set -u to safeguard against potentially undefined variables
  • Enable set -f to safeguard against glob portability issues
  • Enable set -o pipefail to safeguard against failures during piped aggregate commands

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