title: Passing shell script variables to find
body: <p>I'm working on recursively renaming directories and files in a directory.</p>
  
  <pre><code>alan/
      alan_0001.txt
      alan_0002.txt
  andy/
      andy_0001.txt
      andy_0002.txt
  andytwo/
      andytwo_0001.txt
      andytwo_0002.txt
  </code></pre>
  
  <p>I have a tab delimited file (hopefully reproduced here) that supplies new information for file names; e.g.</p>
  
  <pre><code>alan     123_123     Alan's Place
  andy     124_010     Andy's Place
  andytwo     125_001     Andy's Second Place
  </code></pre>
  
  <p>I've worked out the following shell script, but I'm not sure how to pass values from early in the script to find at the end.</p>
  
  <pre><code>#!/bin/sh
  
  FILE="sample-list.txt"
  
  exec 3&lt;&amp;0
  exec 0&lt;$FILE
  
  while read line
  do
      echo $line
      oldName=`echo "$line" | cut -f1`
      adminDB=`echo "$line" | cut -f2`
      title=`echo "$line" | cut -f3`
      echo "$oldName is old, his number is $adminDB, and the title is $title"
      echo "renaming files"
  #    echo find -name '{$oldName}*' 
      echo "`find ./ -name '${oldName}*'`"
  done
  exec 0&lt;&amp;3
  </code></pre>
  
  <p>I'd like to throw the wildcard on <code>$oldName</code> to catch the andy_0001, _0002 files and rename them with <code>find ./ -name ${oldName}* -exec rename $oldName $adminDB {} \;</code></p>
  
  <p>Thanks in advance!</p>