Skip to content

Files

Latest commit

 

History

History
36 lines (24 loc) · 1.1 KB

SC2211.md

File metadata and controls

36 lines (24 loc) · 1.1 KB

Pattern: Use of glob as a command name

Issue: -

Description

You are using a glob as a command name. This is usually a mistake caused by one of the following:

  • Trying to use `*foo*` or $(*foo*) to expand a glob.
  • Using var=$(*.txt) instead of var=(*.txt) to assign an array.
  • Using $(..) instead of ${..} when expanding an array element.
  • Running a program with a name or directory that contains glob characters without escaping them.

Example of incorrect code:

for f in $(*.png); do echo "$f"; done   # Trying to loop over a glob
array=$(*.txt)                          # Trying to assign an array
echo "$(array[1])"                      # Trying to expand an array

Example of correct code:

for f in *.png; do echo "$f"; done
array=(*.txt)
echo "${array[1]}"

Exceptions

None. If you want to specify a command name via glob, e.g. to not hard code version in ./program-*/foo, expand to array or parameters first to allow handling the cases of 0 or 2+ matches.

Further Reading