shopt -s nullglob nocaseglob
set -- [a]bc/
if [ "$#" -gt 0 ]; then
echo 'There is at least one directory called "abc" (case ignored):'
printf '\t%s\n' "$@"
bash shell options
nocaseglob are used here to test whether any directory matching the pattern
[a]bc/ exists case-insensitively. The
nullglob option ensures that the pattern expands to an empty string if there is no match, and the
nocaseglob makes pattern matches case insensitive.
[a]bc/ instead of just
abc to invoke filename matching against directories only. With
[a] we force the shell to glob and pick up all matching names (not just
abc, which, since we are doing case-insensitive globbing, may not actually exist) and with the trailing
/ we restrict the match to directories only. (
abc/ would be set as-is, with no globbing.) Doing this as an argument to
set sets the positional parameters to the matching directory names. These are then available in
$@ and the number of matches is found in
$ mkdir abc aBc ABc # create three directories with only case diffs in their names
$ touch abC # ... and also a file
$ bash ./script.sh
There is at least one directory called "abc" (case ignored):