Run shell command from child shell Run shell command from child shell shell shell

Run shell command from child shell


You can setup in a group, like.

#!/bin/bash(Command1Command2etc..)subshell() {    echo "this is also within a subshell"}subshell

( and ) creates a subshell in which you run a group of commands, otherwise a simple function will do. I don't know if ( and ) is POSIX compatible.

Update: If I understand your comment correctly, you want to be using -c option with bash, like.

/bin/bash -c "Command1 && Command2...." &


From http://tldp.org/LDP/abs/html/subshells.html here is an example:

#!/bin/bash# subshell-test.sh(# Inside parentheses, and therefore a subshell . . .while [ 1 ]   # Endless loop.do  echo "Subshell running . . ."done)#  Script will run forever,#+ or at least until terminated by a Ctl-C.exit $?  # End of script (but will never get here).