shell 脚本中的函数未正确执行

Function in shell script not executed correctly

我为 start/stop/restart 自定义服务器应用程序编写脚本。

启动守护程序服务器时,它应该执行以下操作:

#!/bin/sh -e
### BEGIN INIT INFO
...
...
### END INIT INFO

# Start service
pga_server_start()
{
        /opt/pga/server/server -d
}


# Stop  service
pga_server_stop()
{
        PID=`cat /var/lock/pga_server.lock`
        /bin/kill --signal SIGTERM $PID
}

pga_load_excalibur()
{
        is_loaded=`lsmod | grep excalbr`
        echo "Done"


        if [ -z "$is_loaded" ]; then
                /usr/local/bin/excload
                echo "Driver excalibur loaded."
        else
                echo "Driver excalibur already loaded."
        fi
}

case "" in
        start)
        pga_load_excalibur
        pga_server_start
        ;;
...
...

最初它运行良好。然后我添加了 pga_load_excalibur 函数。 之后,它不再起作用了。 它从不从函数 pga_load_excalibur 中 returns。 似乎调用 is_loaded=lsmod | grep excalbrnever returns as the subsequentecho` 从不打印。

但是,如果我 copy/paste 在单独的 shell 脚本中使用此功能...它可以工作。

但是如果我以这种方式手动启动启动脚本:

/etc/init.d/server开始 要么 服务服务器启动

它不起作用。 我使用的是 Debian Wheezy 7.9 x64。

虽然我不是 schell 脚本,但它看起来是正确的。我不明白为什么当它嵌入到这个服务启动脚本中时它不起作用。

请注意,我还尝试将 grep 行替换为:

is_loaded=$(lsmod | grep excalbr)

但是也不行。 我 运行 没有想法:(

Z.

如果您 运行 脚本处于调试模式,您会得到什么?尝试 运行 它:

#!/bin/sh -xv

这可能会给出失败原因的一些想法,post 如果您无法理解,请输出