mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2144 (markdown)
17
SC2144.md
17
SC2144.md
@@ -45,9 +45,24 @@ for f in /path/to/your/files*; do
|
|||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Exceptions
|
### 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:
|
### Related resources:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user