Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-11-2011, 10:58 PM   #1
LQ Newbie
Registered: Jan 2011
Posts: 12

Rep: Reputation: 0
Bash question

I'm trying to put the date in the name of my file but cant seem to get it I just end up with the word date in the file instead of the date. my script looks like this.
top > $x$y.txt
Old 04-11-2011, 11:16 PM   #2
LQ Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 14,272
Blog Entries: 24

Rep: Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895
I think your variable declaration needs some work.

Here's a snippet from a script I wrote to backup my blog database. First, I created a directory to hold the backup, then I ran mysqldump and dumped the backup into that variable.

I am not a coder and I'm sure there was a better way, but this worked. In this case, I wanted the hour and minute in the directory name.

#Set the variable DATE


#Define now as today’s day-month-year-hour-minute.

DATE=$(date +%m-%d-%Y-%H-%M)

#Make the directory to hold the backup file.

mkdir /root/backups/sql/$DATE
See this: It's excellent.
Old 04-11-2011, 11:45 PM   #3
Registered: Sep 2010
Distribution: Fedora, Android, CentOS
Posts: 91
Blog Entries: 2

Rep: Reputation: 21
Check out the man page for date
#! /bin/bash
post=`date '+%Y:%m:%d'`
echo "$pre$fname$post$ext"
Give this a try and alter as necessary.
Old 04-11-2011, 11:55 PM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,643

Rep: Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961
So the examples provided by other's are where you need to go, but in relation to your own script lines, the following is your error:
y=date  # this says to set y equal to the string 'date'

y=$(date)  # whereas this says to execute the command (could be a function of your own as well) and assign the value returned to y
Hope that helps


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
A question about BASH operand Linux - Newbie 2 11-27-2005 10:49 PM
Bash question lnxduck Programming 3 09-30-2005 09:50 AM
bash question? shanenin Linux - Software 1 11-26-2004 01:22 PM
Bash question Warmduvet Programming 4 09-24-2004 09:19 PM
bash question rjcrews Linux - Newbie 2 08-04-2004 10:46 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:21 PM.

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