Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running shell script command after executing an application

Tags:

linux

shell

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

like image 691
czchlong Avatar asked Feb 28 '26 12:02

czchlong


1 Answers

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:

  • http://unixhelp.ed.ac.uk/CGI/man-cgi?sh
  • http://www.gnu.org/s/bash/manual/bash.html#Job-Control-Builtins
like image 119
sehe Avatar answered Mar 03 '26 04:03

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!