Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run two loops at the same time?

Tags:

bash

shell

So I have a project in my cyber security class to make a bash game. I like to make one of those medieval games where you make farms and mines to get resources. Well I like to make something like that. To do that I have to have two while loops running. Like this

while [ blah ]; do

    blah

done

while [ blah ]; do

    blah    

done

Is it possible to run two while loops at the same time and if I am writing it wrong how do I write it?

like image 800
Lifetake Avatar asked Oct 17 '25 10:10

Lifetake


1 Answers

If you put a & after each done, like done&, you will create new processes in the background that run the while loops. You will have to be careful to realize what this means though, since the bash script will continue executing commands after creating those new processes even if they are not finished. You might use the wait command to prevent this from happening, but I'm not too used to using that so I cannot vouch for it.

like image 112
Victor Zamanian Avatar answered Oct 19 '25 01:10

Victor Zamanian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!