3

I have written a shell script to execute a series of commands. One of the commands in the shell script is to launch an application. However, I do not know how to continue running the shell script after I have launched the application.

For example:

...
cp somedir/somefile .
./application
rm -rf somefile

Once I launched the application with "./application" I am no longer able to continue running the "rm -rf somefile" command, but I really need to remove the file from the directory.

Anyone have any ideas how to compete running the "rm -rf" command after launching the application?

Thanks

4 Answers 4

4

As pointed out by others, you can background the application (man bash 'job control', e.g.).

Also, you can use the wait builtin to explicitely await the background jobs later:

 ./application &
 echo doing some more work

 wait # wait for background jobs to complete 
 echo application has finished

You should really read the man pages and bash help for more details, as always:

Sign up to request clarification or add additional context in comments.

Comments

2

Start the application in the background, this way the shell is not going to wait for it to terminate and will execute the consequent commands right after starting the application:

./application &

In the meantime, you can check the background jobs by using the jobs command and wait on them via wait and their ID. For example:

$ sleep 100 &
[1] 2098
$ jobs
[1]+  Running                 sleep 100 &
$ wait %1

Comments

1

put the started process to background:

./application &

Comments

1

You need to start the command in the background using '&' and maybe even nohup.

nohup ./application > log.out 2>&1 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.