background preloader

UNIX

Facebook Twitter

Bash Sub Shells. When writing bash scripts you sometimes need to run commands in the background. This is easily accomplished by appending the command line to be run in the background with an ampersand "&". But what do you do if you need to run multiple commands in the background? You could put them all into a separate script file and then execute that script followed by an ampersand, or you can keep the commands in your main script and run them as a sub-shell.

Creating sub-shells in bash is simple: just put the commands to be run in the sub-shell inside parentheses. This causes bash to start the commands as a separate process. Advanced Bash Shell Scripting Guide - Using exec. Advanced Bash Shell Scripting Guide - Test Constructs.