title: Dynamic variable names in Bash
body: <p>I am confused about a bash script.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>function grep_search() {
      magic_way_to_define_magic_variable_$1=`ls | tail -1`
      echo $magic_variable_$1
  }
  </code></pre>
  
  <p>I want to be able to create a variable name containing the first argument of the command and bearing the value of e.g. the last line of <code>ls</code>.</p>
  
  <p>So to illustrate what I want:</p>
  
  <pre><code>$ ls | tail -1
  stack-overflow.txt
  
  $ grep_search() open_box
  stack-overflow.txt
  </code></pre>
  
  <p>So, how should I define/declare <code>$magic_way_to_define_magic_variable_$1</code> and how should I call it within the script?</p>
  
  <p>I have tried <code>eval</code>, <code>${...}</code>, <code>\$${...}</code>, but I am still confused.</p>