Skip to content

Files

Latest commit

 

History

History
35 lines (23 loc) · 804 Bytes

SC2231.md

File metadata and controls

35 lines (23 loc) · 804 Bytes

Pattern: Missing expansion quoting in for loop glob

Issue: -

Description

When iterating over globs containing expansions, you can still quote all expansions in the path to better handle whitespace and special characters.

Make sure glob characters are outside quotes. "$dir/*.txt" will not glob expand, but "$dir"/*.txt or "$dir"/*."$ext" will.

Example of incorrect code:

for file in $dir/*.txt
do
  echo "Found $file"
done

Example of correct code:

for file in "$dir"/*.txt
do
  echo "Found $file"
done

Exceptions

If the variable is expected to contain globs, such as if dir="tmp/**" in the example, you can ignore this message.

Further Reading