I have written a bash script to run a service in background and exit from the script to command line. But after running the eval command, control does not go the next statement.
COMMAND="nohup java -jar jenkins.war"
echo "starting service"
eval $COMMAND
echo "service running"
exit
echo "service running" and exit never happens. I want to run the process in the background, and return to the command prompt while the service is still running. How do I do this?
eval is a built in linux or unix command. The eval command is used to execute the arguments as a shell command on unix or linux system. Eval command comes in handy when you have a unix or linux command stored in a variable and you want to execute that command stored in the string.
Splunk eval command. In the simplest words, the Splunk eval command can be used to calculate an expression and puts the value into a destination field. If the destination field matches to an already existing field name, then it overwrites the value of the matched field with the eval expression's result.
On Unix-like operating systems, eval is a builtin command of the Bash shell. It concatenates its arguments into a single string, joining the arguments with spaces, then executes that string as a bash command.
Evaluate several commands/arguments. Syntax eval arg ... The args are read and concatenated together into a single command. This command is then read and executed by the shell, and its exit status is returned as the value of eval.
Please, don't put a command with its arguments in a string. Put your command and its arguments in an array (and don't use upper-case variable names, that's a terribly bad practice), and do not use eval
. eval
is evil!
command=( nohup java -jar jenkins.war )
echo "starting service"
"${command[@]}" 2> /dev/null &
echo "service running"
The &
is to have the command running in background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With