bash脚本语法错误:单词意外(期待"做")

时间:2014-04-03 22:03:53

标签: bash nginx

我正在尝试在我的nginx服务器上运行此Dropbox脚本,但是我得到了:

 Syntax error: word unexpected (expecting "do")

我复制粘贴网站的脚本,我尝试删除特殊字符,但我仍然得到相同的错误。

脚本:

#!/bin/sh
# /etc/init.d/dropbox
### BEGIN INIT INFO
# Provides:          dropbox
# Required-Start:    $network $syslog $remote_fs
# Required-Stop:     $network $syslog $remote_fs
# Should-Start:      $named $time
# Should-Stop:       $named $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop the dropbox daemon for debian/ubuntu
# Description:       Dropbox daemon for linux
### END INIT INFO

DROPBOX_USERS="root"
start() {
    echo "Starting dropbox..."
    for dbuser in $DROPBOX_USERS; do
        start-stop-daemon -b -o -c $dbuser -S -x /home/$dbuser/.dropbox-dist/dropboxd
    done
}

stop() {
    echo "Stopping dropbox..."
    for dbuser in $DROPBOX_USERS; do
        start-stop-daemon -o -c $dbuser -K -x /home/$dbuser/.dropbox-dist/dropboxd
    done
}

status() {
    for dbuser in $DROPBOX_USERS; do
        dbpid=`pgrep -u $dbuser dropbox`
        if [ -z $dbpid ] ; then
            echo "dropboxd for USER $dbuser: not running."
        else
            echo "dropboxd for USER $dbuser: running."
        fi
    done
}


case "$1" in
  start)
    start
    ;;

  stop)
    stop
    ;;

  restart|reload|force-reload)
    stop
    start
    ;;

  status)
    status
    ;;

  *)
    echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
    exit 1

esac

exit 0

2 个答案:

答案 0 :(得分:11)

您可能在复制和粘贴时设法插入了Windows行结尾。如果您有dos2unix,请使用它。 (dos2unix scriptfile)否则,有许多类似的实用程序。

答案 1 :(得分:-1)

为什么有

/home/$dbuser/.dropbox-dist/dropboxd

或替换变量。

/home/root/.dropbox-dist/dropboxd

不应该

/root/.dropbox-dist/dropboxd

例如

/$dbuser/.dropbox-dist/dropboxd

您是否认真考虑/root中的收件箱?

为什么for dbuser in DROPBOX_USERS; do重新分配?而不是

dbuser=$DROPBOX_USERS