title: Bash - Get the VALUE of 'nested' variable into another variable [Edit: Indirect Variable Expansion]
body: <p>I'm trying to get get the VALUE of a 'nested' variable into another variable and/or use the value directly as shown below</p>
  
  <p><strong><em>Below is an example scenario which exactly explains where I'm stuck</em></strong> </p>
  
  <pre><code>$ USER1_DIR=./user1/stuff
  $ USER2_DIR=./user2/stuff
  $ USER3_DIR=./user3/stuff
  
  #User will be taken as input, for now assuming user is USER1 
  $ USER="USER1"
  $ DIR=${USER}_DIR
  
  $ echo $DIR
  &gt;&gt; USER1_DIR
  
  $ DIR=${${USER}_DIR}
  &gt;&gt; -bash: ${${USER}_DIR}: bad substitution
  </code></pre>
  
  <blockquote>
    <p>Challenge 1: </p>
    
    <p>Get DIR value to ./user1/stuff when the input is USER1</p>
    
    <p>or</p>
    
    <p>Get ./user1/stuff as output when the input is USER1</p>
  </blockquote>
  
  <p>After I'm able to get through Challenge 1, I've to add some content to a file in the user directory like below</p>
  
  <hr>
  
  <blockquote>
    <p>Desired output is as below</p>
  </blockquote>
  
  <hr>
  
  <pre><code>$ echo "Some stuff of user1" &gt;&gt; $DIR/${DOC}$NO
  
  # Lets say DOC="DOC1" and NO="-346"
  # So the content has to be added to ./user1/stuff/DOC1-346
  # Assume that all Directories exists
  </code></pre>
  
  <p><em>FYI, The above code will be a part of a function in a bash script and it will be executed only on a Linux server.</em></p>
  
  <p><strong><em>Note : I don't know what to call variable DIR hence used the term 'nested' variable. It would be great to know what is it called, greatly appreciate any insight. :)</em></strong></p>