let's eat our own—SC2250—dog food

Andrei Korshikov
2025-01-27 22:59:50 +06:00
parent 6c141e77af
commit df2c49bdd9

@@ -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: ### Problematic code:
```sh ```sh
for file in $dir/*.txt for file in ${dir}/*.txt
do do
echo "Found $file" echo "Found ${file}"
done done
``` ```
### Correct code: ### Correct code:
```sh ```sh
for file in "$dir"/*.txt for file in "${dir}"/*.txt
do do
echo "Found $file" echo "Found ${file}"
done 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. 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: ### Exceptions: