Updated SC2144 (markdown)

Vidar Holen
2022-02-25 20:01:02 -08:00
parent 943b6071f7
commit af678fe7b3

@@ -45,9 +45,24 @@ for f in /path/to/your/files*; do
done
```
### Exceptions
If filename expansion (globbing) is disabled (`set -f`), then the `[` statement works as expected.
If you are sure there will only ever be exactly 0 or 1 matches -- and `nullglob` is not enabled -- then the test happens to work.
You may still want to consider making this assumption explicit and failing fast if it's ever violated:
```
files=( dir/file* )
[ "${#files[@]}" -ge 2 ] || exit 1
if [ -e "${files[0]}" ]
then
echo "The file exists"
else
echo "No such file"
fi
```
### Related resources: