Re: [ -d (#i)Temp ]
Bart Schaefer <[email protected]> Fri, 10 Apr 2026 11:46:59 -0700
| Newsgroups | gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <CAH+w=7aX4coQBSVLj7eid6snQem72xDCXZEk5aNmKDoNeTXodA@mail.gmail.com> |
On Fri, Apr 10, 2026 at 10:53 AM S. Cowles <[email protected]> wrote: > > On Fri, 10 Apr 2026, Ray Andrews wrote: > > From: Ray Andrews <[email protected]> > > Subject: [ -d (#i)Temp ] > > Is it possible to do something like this:? > > [ -d (#i)Temp ] && echo 'it's a directory' > > ... that doesn't work That should work. It does for me (assuming NO_NULL_GLOB). Try it with setopt xtrace to see what's actually being executed. A better construction might be to use the "test" builtin: test -d (#i)Temp && echo "it's a directory" You'll get an error code ($? == 2) if the glob returns more than one match, or ($? == 1) when not a directory. There is a possibility of confusion if the glob returns a file name starting with a hyphen. > [[ -d ${:-"$( echo (#i)Tmp )"} ]] && echo "it's a directory" || echo no such dir You don't need the ${:-...} around that, but ... > notes: > 1) single brackets are bash / sh (more overhead). double brackets are the zsh builtin. Single bracket is also a zsh builtin, effectively just an alias for "test". There's more overhead from $(...) than from the brackets. > 2) quoting on the return message. Also not really necessary with [[ ]] and in fact ${:-...} forces a single string replacement already. Finally "[" and "test" do globbing on their arguments, "[[" does not, which is why the $(...) is needed.