title: creating environment variable with user-defined name - indirect variable expansion
body: <p>I am trying to create an environment variable in bash script, user will input the name of environment variable to be created and will input its value as well.</p>
  
  <p>this is a hard coded way just to elaborate my question : </p>
  
  <pre><code>#!/bin/bash
  echo Hello 
  export varName="nameX" #
  echo $varName 
  export "$varName"="val" #here I am trying to create an environment 
  #variable  whose name is nameX and assigning it value val
  echo $nameX 
  </code></pre>
  
  <p>it works fine
  it's output is :</p>
  
  <pre><code>Hello
  nameX
  val
  </code></pre>
  
  <p>But, I want a generic code. So I am trying to take input from user the name of variable and its value but I am having trouble in it. I don't know how to echo variable whose name is user-defined</p>
  
  <pre><code>echo "enter the environment variable name"
  read varName
  echo "enter the value to be assigned to env variable"
  read value
  export "$varName"=$value
  </code></pre>
  
  <p>Now, I don't know how to echo environment variable 
  if I do like this :</p>
  
  <pre><code>echo "$varName"
  </code></pre>
  
  <p>it outputs the name that user has given to environment variable not the value that is assigned to it. how to echo value in it?</p>
  
  <p>Thanks</p>