Reputation: 47377
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?
Upvotes: 1
Views: 2117
Reputation: 77400
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.
Upvotes: 1