How to run a program inside a shell script and continue the shell script, although the program remains open

I am using bash in Ubuntu. I want the shell script to open the program and continue to the next line of the shell script, although the program has not been completed.

+6
source share
4 answers

Adding the & command to the command puts it in the background.

Example:

 /path/to/foo /path/to/bar # not executed untill foo is done /path/to/foo & # in background /path/to/bar & # executes as soon as foo is started 

More about work control here and here

+6
source

Use something like this (my-long-running-process &) . This will run your script as a separate process in the background.

+2
source

http://ubuntuforums.org/showthread.php?t=1657602

It looks like all you have to do is add a to the end of the line.

+1
source

You must start the process in the background, but first you need to enable job management. Otherwise, you cannot kill or bring the process to the forefront if you want.

To enable job management:

 set -m 

To perform some task in the background, do:

 task & 

To control the background task, use the syntax jobspec ( %[n] ). For example, to kill the last running process, do:

 kill % 

Please note that enabling job control is only required if you are really using a script (as indicated in the question). If you are working online, job control is already enabled by default.

The mask for bash has much more information in the MANAGEMENT WORK section.

+1
source

Source: https://habr.com/ru/post/894331/


All Articles