title: How to update a variable value from a loop A to another loop B - in bash
body: <p>I am increasing the value of a variable in a first loop and using it in a second loop.</p>
  
  <p><strong>My problem:</strong> the variable doesn't change in the second loop. (It's an example, I know that I can move the code that changes the value from the loop into the function but I have a program with multiple functions and multiple loops).</p>
  
  <p><strong>My question:</strong> how to update the value of a variable (increasing inside a first while loop) in a second while loop? </p>
  
  <p>Here is an <strong>illustration</strong> (First loop is increasing the counter_value but the second loop stick to "1") :</p>
  
  <pre><code>#!/bin/bash
  
  counter_value="1"
  
  function Print_counter_value () {
      echo $counter_value ; }
  
  #_____FIRST LOOP_____
  while : ; do # infinite loop
        #echo first loop works
        counter_value=$[$counter_value+1]
        echo $counter_value 1st_loop &amp; sleep 2
  done &amp;
  
  #_____SECOND LOOP_____
  while : ; do # infinite loop
        #echo second loop works
        Print_counter_value &amp; sleep 1
  done &amp;
  </code></pre>
  
  <p>Thank you!</p>