10

This question already has an answer here:

This question is about ZSH, not bash.

I have the following lines in my .zshrc file. Whenever I open a terminal I get a no matches found error referencing the line with the if 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.

marked as duplicate by Gilles zsh Aug 23 '15 at 23:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    @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. – Stéphane Chazelas Aug 24 '15 at 13:09
  • @StéphaneChazelas How are they not duplicates? Both are asking why [ … ] doesn't work without spaces inside. – Gilles Aug 24 '15 at 13:13
  • 3
    @Gilles, one is about the [ command, the other one about the [[...]] construct, one is about bash, the other one is about zsh. 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 Aug 24 '15 at 13:19
  • 1
    @Gilles, also note that all of bash, ksh93 and mksh do support [[(a == b)]] (not [[!(a == b)]]), not zsh. – Stéphane Chazelas Aug 24 '15 at 13:35
12

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
  • 6
    for ADHD people like me, the solution is [[ -a FILE_NAME ]], the "! -a" asks if the file does not exist. – azorius Feb 9 '17 at 7:47
  • 1
    @azorius My initial question was asking how to test if a file does not exist. – Dave F May 11 '17 at 17:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.