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 is removed if there is no match (it is otherwise left unexpanded), 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 perform globbing and thereby pick up all matching names, and with the trailing
/ we restrict the matching to directories only. 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):