1 SC2266
Vidar Holen edited this page 2022-11-02 20:20:59 -07:00

Use && for logical AND. Single & will background and return true.

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!