diff --git a/SC2144.md b/SC2144.md index 6d4c7eb..5a83ddd 100644 --- a/SC2144.md +++ b/SC2144.md @@ -30,10 +30,26 @@ 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. ### 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) \ No newline at end of file +* [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) \ No newline at end of file