Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: bash custom variable  (Read 3891 times)

0 Members and 1 Guest are viewing this topic.

dthscyth

    Topic Starter


    Rookie

    bash custom variable
    « on: December 28, 2010, 08:21:42 PM »
    I have a bash script that backups database. What I want to do is save the file with its name and the current date. Here is my script.

    #!bash/sh
    #
    MYDATETIME=;date +%Y-%m-%d

    mysqldump -uroot -pdthscyth jobs > jobs_$MYDATETIME.sql


    The problem is when saving the file the value of the variable is not saved. Instead of jobs_2010-12-29.sql the filename is jobs_.sql. Please help. Thanks and Happy New Year!. :D


    dthscyth

      Topic Starter


      Rookie

      Re: bash custom variable
      « Reply #1 on: December 29, 2010, 12:35:15 AM »
      I figure it out. Commands like date should be inside a back quote (`) so instead of

      mysqldump jobs > jobs_$MYDATETIME.sql

      it should be...

      mysqldump jobs > jobs_`date +%Y-%m-%d.sql`