Skip to content

Files

Latest commit

 

History

History
51 lines (35 loc) · 1.07 KB

SC2215.md

File metadata and controls

51 lines (35 loc) · 1.07 KB

Pattern: Use of flag as command name

Issue: -

Description

You are using a name that starts with a dash as a command name. This is almost always a bug.

There are two typical ways in which this happens:

  • Missing [ .. ] or [[ .. ]] around a test expression, like in the first example example.
  • An invalid line break that splits a command in two, like in the second example.

Example of incorrect code:

if -e .bashrc
then
  echo ".bashrc already exists"
fi

or

find . -name '*.mkv'
       -exec mplayer {} \;

Example of correct code:

if [ -e .bashrc ]
then
  echo ".bashrc already exists"
fi

or

find . -name '*.mkv' \
       -exec mplayer {} \;

Exceptions

If you actually have a command that starts with a dash -- which you should really reconsider -- you can quote the name (or at least the leading dash). This makes no difference to the shell, but makes it clear to ShellCheck and humans that this is not intended as a flag.

Further Reading