views:

284

answers:

2

I'm trying to build a Synergy AutoStart script as per this article, the shell is giving me the error

Syntax Error

Expected end of line, etc. but found unknown token

Here is the script I'm working on...

#!/bin/sh
. /etc/rc.common

run=(/usr/local/bin/synergyc -n $(hostname -s) -1 -f 192.168.0.108)

KeepAlive ()
{
 proc=${1##*/}

 while [ -x "$1" ]
 do
  if ! ps axco command | grep -q "^${proc}\$"
  then
   "$@"
  fi
   sleep 3 
 done
}

StartService ()
{
 ConsoleMessage "Starting Synergy"
 KeepAlive "${run[@]}" &
}

StopService ()
{
 return 0
}

RestartService ()
{
 return 0
}

RunService "$1"

And when the error is thrown, the "period" is highlighted on this line . /etc/rc.common

Is there something I'm missing here?

+1  A: 

try dos2unix on the file if you've been editing on a windows machine.

ksm
It was a combination of @Isaac's answer above as well as yours. Thanks... working now.
rockinthesixstring
+1  A: 

Note the particular problem was line endings. Unixen use the line-feed character (LF), Macs traditionally use carriage-return (CR), MS OSs use CR LF. With the wrong line-endings, the shell sees the entire shell script as as single line; CRs aren't considered whitespace and are tokenized. Hence the message that the shell "expected end of line, [...] but found unknown token". Running the script through dos2unix fixes the line endings.

Read Apple's "Shell Scripting Primer". Among other things, it tells you how to use Text Edit.app (and pico and nano, from the command line) to write shell scripts. Alternatively, learn to use Aquamacs or Vim for OS X.

outis
The version of MacVim to which you linked is fairly old. The current (though unrelated) MacVim is at http://code.google.com/p/macvim/
Isaac
Thanks. Updated.
outis