I'm trying to use zsh in a more efficient way and therefore I ask for help.
In a script I am searching for a filename, e.g. foo which can be written in upper or lowercase, like:
- foo
- Foo
- FOo
Afterwards I execute a command using the first found filename as an argument.
To to this task I used the following command lines:
FILE=$(find . -maxdepth 1 -type f -iname foo -print -quit)
command-dummy ${FILE}
I'm pretty sure that there exists a more efficient way and asking for advice and maybe a code with style.
CodePudding user response:
zsh
pathname expansion can handle this without using find
, if you enable the EXTENDED_GLOB
option.
setopt EXTENDED_GLOB
command-dummy (#i)foo(.)
(#i)
(after enabling extended globbing) makes the pattern match case-insensitive, and (.)
restricts matches to regular files.
See man zshexpn
for more information.