Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Silly question on :h and = expansion
- X-seq: zsh-users 26945
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zach Riggle <zachriggle@xxxxxxxxx>, Roman Neuhauser <neuhauser@xxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Silly question on :h and = expansion
- Date: Wed, 18 Aug 2021 04:55:05 +0200
- Archived-at: <https://zsh.org/users/26945>
- In-reply-to: <CAH+w=7a0mQ9xDXvE2QAVdt8FV9FLtziU4csAwWXSgESDyQbFZw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5m8cBSfzSBgDEvadZFOKNMd7sE-qXFrjCxFKXYj6SDxrQ@mail.gmail.com> <CAH+w=7bCUUEaEEGziJcVvYz4semOPskVngCCKnsLU=OMK6Sacg@mail.gmail.com> <YRwrmlzbKMv8vVAE@isis.sigpipe.cz> <CAH+w=7a5eybKqGC1ia-Pzq_Ru1521bNmS5G3_uDWDcVxBrrtFw@mail.gmail.com> <CAMP9c5mnGHC4tbtLnx6-3tGho6-xEPrmZsr_ntymZg2vqYcP6g@mail.gmail.com> <CAH+w=7a0mQ9xDXvE2QAVdt8FV9FLtziU4csAwWXSgESDyQbFZw@mail.gmail.com>
On 8/18/21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Aug 17, 2021 at 4:27 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>>
>> Awesome!!! These are all wonderful. "=foo(:h)" is the most concise
>> way I see, and fits with my style.
>
> It might be worth noting: That formulation only works in contexts
> where globbing is done, so not e.g. in conditionals.
>
> % [[ -f =zsh ]] && echo yes
> yes
> % [[ -d =zsh(:h) ]] && echo yes || echo no
> no
> % [[ -d ${${:-=zsh}:h} ]] && echo yes || echo no
> yes
You can use this form to enable globbing in conditionals,
% [[ -d =zsh(#q:h) ]] && echo yes || echo no
yes
but using = in conditionals is not very useful anyway since when it
fails it aborts, rather than returning an error (and (N) doesn't
suppress it since it's not a glob),
% [[ -f =bloo ]] || echo no
zsh: bloo not found!
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author