diff --git a/SC2231.md b/SC2231.md index d9df8e6..4db1461 100644 --- a/SC2231.md +++ b/SC2231.md @@ -1,20 +1,20 @@ -## Quote expansions in this `for` loop glob to prevent wordsplitting, e.g. `"$dir"/*.txt` . +## Quote expansions in this `for` loop glob to prevent word splitting, e.g. `"${dir}"/*.txt`. ### Problematic code: ```sh -for file in $dir/*.txt +for file in ${dir}/*.txt do - echo "Found $file" + echo "Found ${file}" done ``` ### Correct code: ```sh -for file in "$dir"/*.txt +for file in "${dir}"/*.txt do - echo "Found $file" + echo "Found ${file}" done ``` @@ -22,7 +22,7 @@ done When iterating over globs containing expansions, you can still quote all expansions in the path to better handle whitespace and special characters. -Just make sure glob characters are outside quotes. `"$dir/*.txt"` will not glob expand, but `"$dir"/*.txt` or `"$dir"/*."$ext"` will. +Just make sure glob characters are outside quotes. `"${dir}/*.txt"` will not glob expand, but `"${dir}"/*.txt` or `"${dir}"/*."${ext}"` will. ### Exceptions: