Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh condition on number results in bad pattern

I have a function that I minified to debug but I cannot see the problem. Here is the minimal code to reproduce the issue:

#!/bin/zsh

ahead=1
if [[ "$ahead" -ne 0 ]]; then
    echo "test"
else
    echo "testelse"
fi

I get from executing this script:

./test:4: bad pattern :[[ 1

I cannot understand where the problem is. If I test it with tio.run, it works! If I copy paste it in console it also works.

If I remove the shebang I get: ./test: line 2: [[ 1: command not found testelse

like image 957
2A-66-42 Avatar asked Jun 24 '17 09:06

2A-66-42


1 Answers

I don't really know how or why but as @justsomebody pointed out in the comments it was some kind of weird whitespace character between [[ and $ahead. Might be vim or something else, if you have any clue what it could have been, it would be nice to know.

Edit: I will add that altgr + space creates the kind of character that leads to this situation.

like image 195
2A-66-42 Avatar answered Nov 16 '22 07:11

2A-66-42