LinuxQuestions.org
Review your favorite Linux distribution.
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 03-26-2005, 10:06 AM   #1
wilku
LQ Newbie
 
Registered: Mar 2005
Distribution: Debian Lenny
Posts: 24

Rep: Reputation: 0
Assign command output to a varible.


Hello

I'm trying to write a bash script that would dump mysql database (script run by cron once a week). I need to name the dump file with a current date like twilk_20050326.sql. I come to a problem at the very beginning trying to create filename varible:
Code:
FILE_NAME=date +twilk_%G%m%d.sql
This one gives an error of command not found: +twilk_%G%m%d.sql
I also tried without a space before "+", with single quotes, double quotes around "date ... .sql". All of them assign value of a string, not executing command.

Thanks for any help
 
Old 03-26-2005, 10:08 AM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Try this:

Code:
FILE_NAME=$( date +twilk_%G%m%d.sql )
or this:

Code:
FILE_NAME=`date +twilk_%G%m%d.sql`
Both of those execute the command, and assign the command's output to FILE_NAME.
 
Old 03-26-2005, 10:13 AM   #3
wilku
LQ Newbie
 
Registered: Mar 2005
Distribution: Debian Lenny
Posts: 24

Original Poster
Rep: Reputation: 0
The first solution works. Thanks!

The second one, with single quotes, doesn't (at least for me). It assignes string value instead of executing command.
 
Old 03-26-2005, 11:56 AM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Those are backquotes in the second example (the key next to the "1" on most U.S. keyboards). They serve the same purpose as the first example; the first one is bash-specific, though, so the backquotes one may be more portable to other scripting environments (if you're concerned at all about that). I prefer the first way, since it's easier to read.
 
  


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
Linux command to assign an ip address seb22 LinuxQuestions.org Member Intro 2 06-12-2005 02:19 AM
Linux command to assign an ip address seb22 Linux - Networking 5 05-24-2005 12:03 PM
Assign a command to 'Alt Gr' itself and 'ˇ' char in UT/Q3A kilgor Linux - Games 0 03-08-2005 03:50 PM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
command output to varible!!! fooforon Programming 3 02-05-2004 08:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:48 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
Open Source Consulting | Domain Registration