From d62c667ab4c0563a9d372919d6ac2d31893812e0 Mon Sep 17 00:00:00 2001 From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Date: Fri, 12 Jun 2020 12:59:05 +0300 Subject: [PATCH] Updated SC2144 (markdown) --- SC2144.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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