Skip to content

Files

Latest commit

 

History

History
50 lines (36 loc) · 1.14 KB

SC1124.md

File metadata and controls

50 lines (36 loc) · 1.14 KB

Pattern: Invalid shellcheck directive for case

Issue: -

Description

You appear to have put a directive before a branch in a case statement.

ShellCheck directives cannot be scoped to individual branches of case statements, only to the entire case, or to individual commands within it. Please move the directive as appropriate.

(It is possible to apply directives to all commands within a { ..: } command group, if you truly wish to apply a directive to multiple commands but not the full case statement.)

Example of incorrect code:

case $? in
  0) echo "Success" ;;
  # shellcheck disable=2154
  *) echo "$cmd $flag returned failure" ;;
esac

Example of correct code:

# Applies to everything in the `case` statement
# shellcheck disable=2154
case $? in
  0) echo "Success" ;;
  *) echo "$cmd $flag returned failure" ;;
esac

or

case $? in
  0) echo "Success" ;;
  *)
     # Applies to a single command within the `case`
     # shellcheck disable=2154
     echo "$cmd $flag returned failure"
     ;;
esac

Further Reading