Say I have a folder with three files:foo1foo2bar1.  If I run list_of_files=$(print foo*)echo $list_of_filesI get: foo1 foo22. If I runlist_of_files=$(print bar*)echo $list_of_filesI get: bar3. However, if I runlist_of_files=$(print other*)echo $list_of_filesI get: zsh: no matches found: other* (the variable $list_of_files is empty though)Is there a way to ask zsh to not complain if it can't match a glob expansion?My goal is to use the mechanism above to silently collect a list of files that match a given glob pattern.
How to silently get an empty string from a glob pattern with no matches
zsh;wildcards
Turn on the null_glob option for your pattern with the N glob qualifier.list_of_files=(*(N))If you're doing this on all the patterns in a script or function, turn on the null_glob option: setopt null_globThis answer has bash and ksh equivalents.Do not use print or command substitution! That generates a string consisting of the file names with spaces between them, instead of a list of strings. (See What is word splitting? Why is it important in shell programming?)