BASH SHELL IF ELSE run command in background
- by bikerben
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.