LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-03-2006, 03:23 AM   #1
Anthraxnz
LQ Newbie
 
Registered: Sep 2005
Posts: 21

Rep: Reputation: 15
making a .tar with a string and a variable name


i need to make a .tar file named "backp_<date>.tar" date being the actual date.

i got this so far:
Code:
DATE=`date +%D` // gets date in format of 11/3/06
i need to make this part work.
Code:
tar -cf backup_$DATE.tar $FILE  //File Being the file or dir name to backup
this is for a shell script, i tried lots of different ways but cant get it to work.

Thanks
Anthrax
 
Old 11-03-2006, 04:29 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

The forward slashes in your string cause problems, it's one of the special characters.
Try not using them, they need to be escaped every time you want to do something with that string (or the created file).

Something like this works:

DATE=`date '+%m-%d-%y'` => Date format will be: 11-03-06
tar -cf backup_$DATE.tar $FILE => filename will be: backup_11-03-06.tar

Hope this helps.
 
Old 11-03-2006, 05:40 AM   #3
Anthraxnz
LQ Newbie
 
Registered: Sep 2005
Posts: 21

Original Poster
Rep: Reputation: 15
thanks works fine.
 
  


Reply


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
Print a part of variable/string p0tw0r Linux - Newbie 1 04-07-2005 03:49 PM
Perl variable string search ugenn Programming 1 05-07-2004 09:19 PM
need to innitialize string variable with multiple spaces clsonnt Programming 3 08-11-2003 11:40 AM
variable to string x2000koh Programming 4 07-30-2003 03:23 AM
Getting a variable name based on a string. jtshaw Programming 7 10-08-2002 03:06 PM


All times are GMT -5. The time now is 01:12 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration