-1

This is the errors I get when I try to run my script

~bin/killp: line 7: [[ menubar: command not found
~bin/killp: line 11: [[ menubar: command not found
~bin/killp: line 11:  [[: command not found
~bin/killp: line 15: [[ menubar: command not found
~bin/killp: line 15:  [[: command not found
~bin/killp: line 15:  [[ menubar: command not found
~bin/killp: line 19: conditional binary operator expected
~bin/killp: line 19: syntax error near `Dock'
~bin/killp: line 19: `if [[ $1 == Dock ]]; then'

This is what these lines look like

if [[ $1 == Desktop ]] || [[ $1 == Finder ]]; then
killall Finder
fi

The only difference is Desktop and Finder. menubar is the argument I am passing to the script, aka $1.

  • 1
    Show use the whole script. It looks like it's not executed by bash. – Arkadiusz Drabczyk Nov 10 '15 at 18:04
  • I have tried to specifically add "bash" before the script, and this (#!/bin/bash) is in the beginning. – DisplayName Nov 10 '15 at 18:05
  • 1
    Copy-paste the whole script. – Gilles Nov 10 '15 at 23:59
3

Based on the error messages, your script probably has some hidden non-breaking space characters (e.g. you typed -space)

e.g. the errors are really something like:

~bin/killp: line 7: [[@menubar: command not found
~bin/killp: line 11: [[@menubar: command not found
~bin/killp: line 11: @[[: command not found
~bin/killp: line 15: [[@menubar: command not found
~bin/killp: line 15: @[[: command not found
~bin/killp: line 15: @[[@menubar: command not found
~bin/killp: line 19: conditional binary operator expected
~bin/killp: line 19: syntax error near `Dock'
~bin/killp: line 19: `if [[ $1 == Dock ]]; then' <-- Somewhere, not sure where.

Where I have replaced the invisible characters with @.

  • I also thought this, so I tried replacing all " [[" with " [[" (yes, the same thing). But I didn't think of the positions like you did. I will check if this is the case. – DisplayName Nov 10 '15 at 18:31
  • @DisplayName AIUI You need the spaces, but they need to be real spaces. What text editor are you using? – Random832 Nov 10 '15 at 18:32
  • yeah of course I need the spaces. I replaced "(space)[[" with the same thing ((space) being " "). (There were spaces in my comment) I use Sublime Text, I have had this problem very often, I don't know why I accidentally make faulty whitespaces. – DisplayName Nov 10 '15 at 18:37
  • My guess is shift + space. – DisplayName Nov 10 '15 at 18:38
  • @DisplayName, it seems to be the space after [[, so try replacing /[[./ with "[[ " – glenn jackman Nov 10 '15 at 19:14
0

In my experience things like this are solved by looking a line or two up in the code and finding something I screwed up.

I just typed out what you gave on a Mac using vim (used echo instead of killall) and it ran just fine and this:

$ more test.sh
#!/bin/sh

if [[ $1 == Desktop ]] || [[ $1 == Finder ]]; then
    echo "Finder"
fi

On a Windows box running cygwin:

petro@<blur> ~
$ ./test.sh

petro@<blur> ~
$ ./test.sh stuffing

petro@<blur> ~
$ ./test.sh Finder
Finder

So the code as written seems fine, your problem is likely above it.

  • Non-breaking spaces don't paste correctly into editing forms in most browsers. – Random832 Nov 10 '15 at 20:35
  • Yeah, but I really didn't see how he could keep getting that. I guess that's what happens when one abandons Gods Own Editor(s) (vi/emacs) in favor of those new fangled things. (J/K) – Petro Nov 11 '15 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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