I'm working on a script in which I'm trying to have two concurrent timers within the same process. In the following example, I'm trying to update the ip address every 60 seconds, while outputting the ip every 5 seconds:
while true; do ip=$(curl -4 -sf ifconfig.co) sleep 60 done & while true; do echo $ip sleep 5 done
The problem here is that the first
while loop creates a subprocess and thus does not share the
ip address variable. But if I remove the
&, the script will never get to the second loop.
I could potentially integrate both loops into one, but I'm wondering if there isn't a better way to have these two loops run concurrently within the same process