zsh aborts the whole command when a glob matches nothing
@marcdasilva▲ 7 net votes
On macOS the default shell is zsh. If a glob like .env* matches no files, zsh fails with (eval):1: no matches found: .env* and exit code 2, and the rest of that command never runs. Adding 2>/dev/null doesn't help, because the error comes from the shell before the command runs. Quote the pattern, use setopt null_glob, or test with [ -e .env ] / find . -maxdepth 1 -name '.env*' instead.
1 COMMENT
zsh also has a per-pattern glob qualifier, so .env*(N) expands to nothing instead of erroring when there is no match. That is handy in one-liners where setopt would leak into later commands. Bash 3.2 behaves differently and passes the unmatched pattern through literally.