Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [ -d (#i)Temp ]
- X-seq: zsh-users 30524
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: [ -d (#i)Temp ]
- Date: Fri, 10 Apr 2026 11:46:59 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/fkIBv6NE5fWCnb80OfzwKAlBeUI/nMyal2XpJENg5s=; fh=hSLUtyVkxbQ84ew/DOQBCr+JU3iz+amDTVKA6VBWyHw=; b=BYiKKFv1ZcyVxxRYZSeMTUpCvlvEOkCspB2IQ9h0uvh7OQd0SnhR0SVy4dcTTfReVZ J/Ldl4KtRYBlFLdijZ3vkUH5VHoautdQqo8BD4RNTyeJy1+q7fVq5uC5Wnq8VMKv+s7Q MfUvLIWmNUpaxZp1OqIH5ASTOkwhDHmJJX4Tqzvja828pNjmpOOgNqKFS2iCX275ZIYX LQsey3HSVnu4tRx2oXL1JG+VMNdmjEYcK6RTIZBg4inyfmbMnd3QAdXwOWsEkJ/dxFfS 7uB53jfdgZCYaam+PbLowjEkIikrl5g4xlc9vr2HSEhrdVND6bAFZrRvsP3CLgmmul1C Md7Q==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1775846832; cv=none; d=google.com; s=arc-20240605; b=kqwLYv6Oy/9Cxsh2bGF9QKWhptan8oQ2l3nrfTrqG0kj/1RA+ZTF3MU0kU2SQVss5n BwYxKRKsbxozvmXnIm+gbEoiUjkd9teDmVcd1YGRuvLpbY6oaeahc4LZG8G5mgZSWAiY KdCqvnPm1a5tiXw9+WT+nb2AyijGFPIXvlhnCa3k27anadX9pFQ5nxb1nJSgbdeSd2HF BFDPTqHh5DpeHbKcrZGKNfgr/EK1gLPTWKSvOAeAZDQcRiSiDQB2kgf8xH2vV12z8cOt gNzwq7CuYZkhuKIFbaOTd2uT48lH/BSKHJGFjhn20A+uPmqFyeg7RC+aQo0RyipyfLun uPlQ==
- Archived-at: <https://zsh.org/users/30524>
- In-reply-to: <1b9ee4e6-26a0-3393-be84-1031794fad1b@sonic.net>
- List-id: <zsh-users.zsh.org>
- References: <dcc675da-fa5b-422c-bd63-748886ff1858@eastlink.ca> <1b9ee4e6-26a0-3393-be84-1031794fad1b@sonic.net>
On Fri, Apr 10, 2026 at 10:53 AM S. Cowles <scowles@xxxxxxxxx> wrote:
>
> On Fri, 10 Apr 2026, Ray Andrews wrote:
> > From: Ray Andrews <rayandrews@xxxxxxxxxxx>
> > 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author