title: Parsing part of a file name to use as a variable in bash
body: <p>I need to get the DB name and use it as a variable from part of a file name. Currently I have it pulling in the name of the file from a <strong>ls</strong> command. This is what it returns:<br>
  Test-20150311-1200.sql<br><br>
  I need the first part of the filename up to the "-" so for this example it would be Test. How can I get just part of the file name for my variable? Below is the full script I am working on. Any help would be great. Thanks.</p>
  
  <pre><code>#!/bin/bash
  DB_USER=x
  DB_PASS=x
  DB=
          for DB_GZFILE in $( ls *.sql.gz ); do
          gunzip $DB_GZFILE
              echo item: $DB_FILE unzipped
      done
          for DB_FILE in $( ls *.sql ); do    
  #Use this statement to insert dump into a new server
          mysql $DB &lt;$DB_FILE
      done    
  #Use this command to insert into a server already in use
  #       mysql -u$DB_USER -p$DB_PASS &lt;$DB_FILE
              echo $DB_FILE inserted into database
      done
  #Remove sql files used to insert into this server
  
  #            rm $DB_FILE
  #           echo $DB_FILE removed
      done
  
              echo restarting the mysql process .....
  #       /etc/init.d/mysql restart
               echo mysql restarted
         done
  </code></pre>