LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-16-2007, 07:36 AM   #1
pueblonative
Member
 
Registered: Jun 2006
Location: Pueblo, Colorado
Distribution: OpenSuse
Posts: 55

Rep: Reputation: 15
Bash scripting using date


Here's the file so far:


Quote:
myfilename = $(date +%m%d%y) + ".tar.gz"
echo $myfilename

And here is the error:

Quote:
./backupfiles.sh: line 1: myfilename: command not found

I know I'm missing something, what is it?
 
Old 01-16-2007, 07:40 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

There are spaces between myfilename and = and $(.......), they should not be there. I.e:

myfilename="$(date +%m%d%y).tar.gz"

I also removed the + bit and changed the quotes.

Hope this helps.
 
Old 01-16-2007, 07:48 AM   #3
pueblonative
Member
 
Registered: Jun 2006
Location: Pueblo, Colorado
Distribution: OpenSuse
Posts: 55

Original Poster
Rep: Reputation: 15
Thanks, that worked.
 
Old 01-16-2007, 10:34 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
By the way, "+%m%d%y" is broken (unsortable and ambiguous), you should use "+%Y%m%d" or "+%F" instead.
 
  


Reply

Tags
bash, command, date, redirection


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] Seeing if a file has been modified before/after a date w3stfa11 Programming 7 10-15-2006 07:02 PM
shell scripting and 'date' matttail Programming 8 05-02-2006 11:56 PM
Shell scripting: Doing MySQL Dump base on date Swakoo Linux - General 2 09-21-2005 11:23 PM
using bash in cron to get the date in filename rstoutmna Programming 1 12-29-2004 03:39 PM
Date in a BASH script... soulsniper Linux - Software 7 11-22-2003 07:08 PM


All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration