Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

control to the next statement after running eval command

Tags:

bash

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?

like image 851
user1164061 Avatar asked Dec 27 '12 22:12

user1164061


People also ask

How does eval command work?

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.

What does eval command do in Splunk?

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.

What does the eval command do in Bash?

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.

What is eval command in Mac?

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.


2 Answers

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.

like image 171
gniourf_gniourf Avatar answered Nov 09 '22 13:11

gniourf_gniourf


Add an ampersand to the end of the call:

eval $COMMAND &
like image 20
Foggzie Avatar answered Nov 09 '22 12:11

Foggzie