首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RETVAL是什么意思?

RETVAL是什么意思?
EN

Stack Overflow用户
提问于 2013-03-14 22:01:38
回答 3查看 48.8K关注 0票数 10

我正在尝试为startstop服务的脚本创建一个模板。我检查了tomcat启动和停止的模板,并看到了命令RETVAL=$?

这是做什么的?我应该留着它吗?顺便说一下,我的脚本在下面,如果你们想看的话。

代码语言:javascript
复制
#!/bin/bash
#===================================================================================
#
#
FILE: <script-file-name>.sh
#
#
USAGE: <script-file-name>.sh [-d] [-l] [-oD logfile] [-h] [starting directories]
#
# DESCRIPTION: List and/or delete all stale links in directory trees.
#
The default starting directory is the current directory.
#
Don’t descend directories on other filesystems.
#
#
OPTIONS: see function ’usage’ below
# REQUIREMENTS: ---
#
BUGS: ---
#
NOTES: ---
#
AUTHOR: Valter Henrique, valter.henrique@<company>.com
#
COMPANY: <company>
#
VERSION: 1.0
#
CREATED: 03.14.13
#
REVISION: 03.14.13
#===================================================================================
#
# chkconfig: 345 90 12
# description: <service-name> start, stop, restart service
#
# Get function from functions library
. /etc/init.d/functions

folder=/<company>/<service-folder> #folder to the application
service="<service-name>" #name of the service

startup=$folder/start.sh
shutdown=$folder/stop.sh


#=== FUNCTION ================================================================
#
NAME: start
# DESCRIPTION: Start the service <service-name>
# PARAMETER 1: ---
#===============================================================================
start() {

  #----------------------------------------------------------------------
  # logging the start
  #----------------------------------------------------------------------
  initlog -c "echo -n Starting $service:"

  #----------------------------------------------------------------------
  # getting the process PID
  #----------------------------------------------------------------------    
  pid_process=`ps -ef | grep "$folder/<jar>.jar" | grep -v grep |awk -F' ' '{ print $2 }'`;

  if [ $pid_process ]; then
    echo "<service-name> is running!"
    echo "Stop then first!"
  else
    action $"Starting <service-name> service: " su - <user_deployer> -c $startup
    RETVAL=$?
  fi
  #----------------------------------------------------------------------
  # create the lock file
  #----------------------------------------------------------------------
  touch /var/lock/subsys/$service
  success $"Sucess $service startup"
  echo
}

#=== FUNCTION ================================================================
#
NAME: stop
# DESCRIPTION: Stop the service <service-name>
# PARAMETER 1: ---
#===============================================================================
stop() {
  #----------------------------------------------------------------------
  # logging the stop
  #----------------------------------------------------------------------
  initlog -c "echo -n Stopping $service: "
  killproc $service
  #----------------------------------------------------------------------
  # now, delete the lock file
  #----------------------------------------------------------------------
  rm -f /var/lock/subsys/$service
  echo
}

#----------------------------------------------------------------------
# Main Logic
#----------------------------------------------------------------------
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $service
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac 
exit 0
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-14 22:03:49

$?给出了上一次执行的命令的状态。在您的示例中,最后执行的命令是action....。此命令的退出状态将显示在稍后在RETVAL变量中捕获的$?中。如果命令成功,$?将包含0,否则为非零值。

票数 25
EN

Stack Overflow用户

发布于 2013-03-14 22:05:46

RETVAL是一个变量。$?正在将上次执行的命令的状态赋给RETVAL变量。

票数 3
EN

Stack Overflow用户

发布于 2013-03-14 22:12:55

正如其他人所说,$?是最后一个命令的退出状态。

现在,关于你的问题...

RETVAL不会在脚本中的其他地方使用,但请记住,在bash中,常规变量是全局变量,因此它们可以被其他函数使用。如您所见,可能会有一个success调用使用它。在我检查过的发行版中,/etc/init.d/functions没有使用这个变量,所以这行代码只是噪声,可以删除。检查你的发行版,看看它是做什么的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15411429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档