title: Improved technique to store a filename in a variable?
body: <p>Greetings,</p>
  
  <p>I need to store the filename of a log into a variable so my script can perform some checks on the daily log files. These logs always have a different name because they have a timestamp in the name. Currently I'm using a hodge podged method that pipes an ls command to sed, sort, cut, and tail in order to get the name out.  </p>
  
  <pre><code>CRON_LOG=$(ls -1 $LOGS_DIR/fetch_cron_{true,false}_$CRON_DATE*.log 2&gt; /dev/null | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &amp;/' | sort -n | cut -d ' ' -f2- | tail -1 )
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>$CRON_DATE is supplied as an argument to the script. It is the date (to the day) that the log was created on. Sometimes multiple logs will exist for the same day so I want this to get the most recent one. </p>
  
  <p>Some typical filenames:<br>
  fetch_cron_false_031810090452.log<br>
  fetch_cron_true_031310090001.log<br>
  etc... </p>
  
  <p>Please keep in mind that this works as is. I just think it is ugly and am trying to find a better way to pull it off.</p>
  
  <p>I'm pretty sure I kluged this together from some stuff I found google a few months ago. it works now but I'm not really happy with the technique. I have some ideas about how to do this better but I have had great success on this site before and thought it might be best to refer to the stackoverflow gods first. All answers are greatly appreciated.</p>
  
  <p>Thanks,
  Ryan  </p>