I am using BASH and I am calling a couple of functions which update a couple of variables. These functions take too long to complete so I was thinking running all of the functions in the background so that they can be running simultaneously.
This is a basic example of what i am asking.
#/bin/bash
func1()
{
var1="one"
}
func2()
{
var2="two"
}
func3()
{
var3="three"
}
echo "Right now this is what i am doing"
func1 &
func2 &
func3 &
wait
echo "The variables are $var1 $var2 $var3"
echo "But the variables are empty.
echo "Hence, I am assuming that they are not accessible outside of the function"
I feel like I am missing something very silly. Of course if I don't run the functions in the background, they show the correct variables.
Thank you in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…