Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: globbing in conditional expressions



On May 7,  2:41pm, Roman Neuhauser wrote:
}
} i was hoping i could combine conditional expressions with
} some globbing, but i'm struggling to find the proper syntax.

Conditional expressions only do pattern matching against strings, they
do not do globbing against file names.  So glob qualifiers like (/F)
have no special meaning in a conditional expression.

The way to handle this is to perform the glob first and then test the
result of globbing, e.g.

    if function { set - foobar(/FN) && [[ -z $1 ]] }
    then print not a directory or empty
    else print directory contains files
    fi

Use a subshell if the version of zsh is old enough not to support anonymous
functions.



Messages sorted by: Reverse Date, Date, Thread, Author