BASH SHELL IF ELSE run command in background

Posted by bikerben on Stack Overflow See other posts from Stack Overflow or by bikerben
Published on 2011-11-15T09:47:32Z Indexed on 2011/11/15 9:51 UTC
Read the original article Hit count: 209

I have used the & command before to make a script run another script in the background like so:

#!/bin/bash
echo "Hello World"    
script1.sh &
script2.sh &
echo "Please wait..."

But lets say I have another script with an IF ELSE statment and I would like to set an ELIF statement mid flow as a background task witht the & and then carry on with processing the rest of my script knowing that while rest of the ELIF will carry running in the back ground:

#!/bin/bash
if cond1; then
stuff
sleep 10 &
stuff
stuff
elif cond2; then
something else
else 
echo "foo"
fi
stuff
echo "Hello World"

I really hope this makes sense any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell