What does RETVAL mean?

I am trying to create a template for start and stop services scripts. I checked the template for tomcat start and stop and saw the command RETVAL=$? .

What does it mean? Should I keep it? By the way, my script is below if you guys want to see this.

 #!/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 
+6
source share
3 answers

$? gives the status of the last command executed. In your case, the last command executed was action.... The exit status of this command will be present in $? which will be later written to the RETVAL variable. If the team was successful, $? will contain 0, otherwise a non-zero value.

+19
source

RETVAL is a variable. $? assigns the status of the last command executed to the RETVAL variable.

+3
source

As others have claimed, $? is the exit status of the last team.

Now, regarding your question ...

RETVAL not used anywhere in the script, but remember that in bash regular variables are global, so they can be used by other functions. As you can see, there is a success call that can use it. In the distribution I checked, /etc/init.d/functions does not use this variable, so the line is just noise and can be removed .. check your distribution to see what it does.

+2
source

All Articles