不知道为什么这个小shell脚本不起作用

tom*_*ted 2 bash shell ubuntu-10.04

我正在尝试制作一个小脚本来为我正在制作的 python 网站启动 gunicorn。我稍微修改了在https://github.com/benoitc/gunicorn/blob/master/examples/gunicorn_rc 上找到的脚本。这是我的版本。

#!/bin/sh

GUNICORN=/usr/local/bin/gunicorn
ROOT=/srv/mobile-site/app
PID=/var/run/gunicorn.pid

APP=mobilecms:app

if [ -f $PID ]; then rm $PID fi        

cd $ROOT
exec $GUNICORN -b 127.0.0.1:8080 -w 8 -k gevent --pidfile=$PID $APP
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行脚本时,它显示此错误

/etc/init.d/gunicorn: 13: Syntax error: end of file unexpected (expecting "fi")
Run Code Online (Sandbox Code Playgroud)

有谁知道出了什么问题?

Jed*_*els 7

rm $PID和之间需要一个分号fi。像这样:

if [ -f $PID ]; then rm $PID; fi 
Run Code Online (Sandbox Code Playgroud)

分号本质上是速记,因此您可以将这个小的 if 语句放在一行中。没有它们,它看起来像这样:

if [ -f $PID ]
then
    rm $PID
fi 
Run Code Online (Sandbox Code Playgroud)