LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-16-2007, 03:18 PM   #1
fultron
LQ Newbie
 
Registered: Apr 2005
Posts: 27

Rep: Reputation: 15
Help with variable assigning in shell scripts


I am currently making a shell script to back up all my data (/home) to /mnt/hda3. I am having a problem, however, with managing to assign a variable a value equal to the output of a command. right now, this is what the script looks like:
#backup of /home to /mnt/hda7
clear
mount /dev/hda7 /mnt/hda7
date=date +$m$d$y
cp -r /home /mnt/hda7/$date
umount /dev/hda7
clear
echo "Backup: ";ls /mnt/hda7/$date

The problem I am having it that the variable date isn't assigned the value of the output of dat +%m%d%y. Any help would be great!
 
Old 02-16-2007, 03:28 PM   #2
tuxrules
Senior Member
 
Registered: Jun 2004
Location: Chicago
Distribution: Slackware64 14.1
Posts: 1,138

Rep: Reputation: 55
Quote:
Originally Posted by fultron
#backup of /home to /mnt/hda7
clear
mount /dev/hda7 /mnt/hda7
date=date +$m$d$y
cp -r /home /mnt/hda7/$date
umount /dev/hda7
clear
echo "Backup: ";ls /mnt/hda7/$date

The problem I am having it that the variable date isn't assigned the value of the output of dat +%m%d%y. Any help would be great!
Try
Code:
date=`date +%m%d%Y`
Note the backticks. BTW, upper case Y and lower case y will give you a different year format. Refer man date for more info.

Hope this helps

Last edited by tuxrules; 02-16-2007 at 03:30 PM.
 
Old 02-16-2007, 04:32 PM   #3
fultron
LQ Newbie
 
Registered: Apr 2005
Posts: 27

Original Poster
Rep: Reputation: 15
thanks!

Yup, I'm familiar with the Unix time format from PHP. The script is working perfectly! Thanks for the quick response -- I love this site! I don't think I've ever worked with anything that has such a dedicated, helpful and friendly user base.
 
  


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
Trouble assigning value to variable with fatsheep Programming 1 11-07-2006 07:44 PM
getting rpoblem in assigning value to variable in if construct Ankit mittal Programming 9 01-07-2006 09:12 AM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 07:58 AM
in C, Assigning output of system() to a variable Miaire Programming 4 01-30-2005 12:40 PM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM


All times are GMT -5. The time now is 04:39 AM.

Main Menu
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