Clone
2
SC2266
Joachim Ansorg edited this page 2025-05-03 16:59:46 +02:00

Use || for logical OR. Single | will pipe.

Problematic code:

if [ "$1" = "--verbose" ] | [ "$1" = "-v" ]
then
  verbose=1
fi

Correct code:

if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]
then
  verbose=1
fi

Rationale:

ShellCheck found a test command followed by a |. This was undoubtedly intended as a logical OR (||).

Exceptions:

None

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!