[ -f "$myregexp" ] or [[ -f $myregexp ]] tests if there's a file called exactly $myregexp. (Note that with the single brackets, you need the double quotes.)
If you want to test for the existence of files matching a glob pattern, there's no direct way. You have to do it in two steps: first generate the list of matches, then test if that list is empty.
a=( ~(Ni)*.@(tgz|tar.gz) )
if [[ ${#a} -ne 0 ]]; then …
This uses a number of ksh-specific features:
- the
~(N) prefix to generate an empty list if there is no match;
- the
~(i) prefix to do case-insensitive matching;
- the
@(foo|bar) glob syntax to match foo or bar
Here's a bash equivalent. In bash, you get case empty expansion for non-matching globs and case insensitivity from options; extglob is for the @(foo|bar) syntax and other ksh glob extensions.
shopt -s nocaseglob nullglob extglob
a=( *.@(tgz|tar.gz) )
if [[ ${#a} -ne 0 ]]; then …
Here's a zsh equivalent. The extended_glob option is needed for the (#i) prefix for a case-insensitive match. The (N) glob qualifier indicates empty expansion for non-matching globs.
setopt extended_glob
a=( (#i)*.(tgz|tar.gz)(N) )
if [[ ${#a} -ne 0 ]]; then …