From df2c49bdd9b8ec007b6f3f3680bb2301cfe099d3 Mon Sep 17 00:00:00 2001 From: Andrei Korshikov Date: Mon, 27 Jan 2025 22:59:50 +0600 Subject: [PATCH] =?UTF-8?q?let's=20eat=20our=20own=E2=80=94SC2250=E2=80=94?= =?UTF-8?q?dog=20food?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SC2231.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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: