How do I test if a file does not exist using ZSH?
17,717
Thanks to don_crissti for answering this for me.
The correct if
block is below.
if [[ ! -a ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE} ]]; then
zkbd
fi
Related videos on Youtube
Author by
Dave F
Updated on September 18, 2022Comments
-
Dave F almost 2 years
This question is about ZSH, not bash.
I have the following lines in my
.zshrc
file. Whenever I open a terminal I get ano matches found
error referencing the line with theif
statement.if [[!( -a ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE} )]]; then zkbd fi
I read through the ZSH documentation and my
if
statement appears to be correct. I don't understand why I'm getting the error.What I'd like to happen is for the
zkbd
utility to run if the file in the.zkbd
folder does not exist.-
Stéphane Chazelas almost 9 years@Gilles, how is that a duplicate? OK, in both cases, adding spaces fixes the problem, but considering as duplicates any question where the solution is to add spaces somewhere sounds wrong to me.
-
Gilles 'SO- stop being evil' almost 9 years@StéphaneChazelas How are they not duplicates? Both are asking why
[ … ]
doesn't work without spaces inside. -
Stéphane Chazelas almost 9 years@Gilles, one is about the
[
command, the other one about the[[...]]
construct, one is aboutbash
, the other one is aboutzsh
. The error messages are completely different (at least it would make sense to explain why you get a no-match error in zsh here). -
Stéphane Chazelas almost 9 years@Gilles, also note that all of
bash
,ksh93
andmksh
do support[[(a == b)]]
(not[[!(a == b)]]
), notzsh
.
-
-
azorius over 7 yearsfor ADHD people like me, the solution is [[ -a FILE_NAME ]], the "! -a" asks if the file does not exist.
-
Dave F about 7 years@azorius My initial question was asking how to test if a file does not exist.
-
Keshav about 2 yearscan I ask what function this is? How do I search for [[ ... ]] in the manual?