mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2144 (markdown)
16
SC2144.md
16
SC2144.md
@@ -30,6 +30,21 @@ done
|
||||
|
||||
Instead, use a for loop to expand the glob and check each result individually.
|
||||
|
||||
If you are looking for the existence of a directory, do:
|
||||
|
||||
```sh
|
||||
for f in /path/to/your/files*; do
|
||||
|
||||
## Check if the glob gets expanded to existing files.
|
||||
## If not, f here will be exactly the pattern above
|
||||
## and the exists test will evaluate to false.
|
||||
[ -e "$f" ] && echo "files do exist" || echo "files do not exist"
|
||||
|
||||
## This is all we needed to know, so we can break after the first iteration
|
||||
break
|
||||
done
|
||||
```
|
||||
|
||||
### Exceptions
|
||||
|
||||
None.
|
||||
@@ -37,3 +52,4 @@ None.
|
||||
### Related resources:
|
||||
|
||||
* [BashFaq: How can I check whether a directory is empty or not? How do I check for any *.mpg files, or count how many there are?](https://mywiki.wooledge.org/BashFAQ/004)
|
||||
* [sh - Check if a file exists with wildcard in shell script - Stack Overflow](https://stackoverflow.com/a/6364244/2309247)
|
Reference in New Issue
Block a user