LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-30-2011, 01:00 PM   #1
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Rep: Reputation: 0
Problem with loading date into variable


I have the following code:
Code:
#!/bin/bash 
	mydate= date
	echo $mydate
	echo $mydate
	echo $mydate
	date
exit
The expected result is to see the date four times.
Instead I get:
Code:
Sat Apr 30 13:41:08 EDT 2011


Sat Apr 30 13:41:08 EDT 2011

Can anyone tell me the reason for this and give me a work around
Thanks Frank
 
Old 04-30-2011, 01:02 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
First of all, you need to remove the space after the =. Secondly, you need to tell Bash to run the command and store the output in the variable. What you're attempting to do is store the text "date" in the variable. What you want to do is the following:

mydate=$(date)

You might want to read more about Bash scripting. A good guide can be found here.
 
1 members found this post helpful.
Old 05-04-2011, 01:18 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Are you still having problems with this?
 
Old 05-07-2011, 10:50 PM   #4
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
Sorry for the delay in replying.
Thanks for your Answer. The reference you sent is invaluable. Can you recommend a good 'dead tree' book? I'm marking it solved.
Problem is I'm very new to Bash scripting, and I'm trying to convert my old C & PHP programs into Bash. I know what I need to do, but I'm having problems with the mechanics.

Frank
 
Old 05-08-2011, 12:29 PM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Cool. Unfortunately, I (personally) am unable to recommend a book on Bash as I only really learnt from the guide I provided a link to. Maybe check out some of the books in the bibliography of said guide, or perhaps Learning the bash Shell. There are probably other good books, too.

Out of interest, though, why are you converting C and PHP programs to Bash?
 
Old 05-08-2011, 01:27 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by boumphreyfr View Post
Can you recommend a good 'dead tree' book?
AFAIK there isn't one; we have moved into the online age and documentation is mostly on the web. There's a list of shell scripting links here and further intros here and here. Bash keeps on getting better (or more bloated, depending on your PoV) so beware that older documentation does not cover newer features. Once you are up to speed (and maybe before) you may find GNU's bash reference useful.
 
Old 05-09-2011, 12:48 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
See also
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 05-09-2011, 02:15 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Another list of tutorials here, with reviews.
 
Old 05-09-2011, 06:38 AM   #9
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 831

Rep: Reputation: 200Reputation: 200Reputation: 200
Dead tree books. These ar every necessary in India (where I come from). Sometimes you commute upto two hours a daya - daily. So leaves little time for using the computer (and most people cant afford laptops).

"The UNIX programming environment" by Kernigan and Pyke.

OK
 
Old 05-09-2011, 07:48 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by AnanthaP View Post
Dead tree books. These ar every necessary in India (where I come from). Sometimes you commute upto two hours a daya - daily. So leaves little time for using the computer (and most people cant afford laptops).

"The UNIX programming environment" by Kernigan and Pyke.

OK
If the demand is there then some enterprising person (no shortage of those in India!) will produce them. Alternatively you could download the online pages and print them onto dead trees yourself ...
 
Old 05-09-2011, 01:27 PM   #11
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Original Poster
Rep: Reputation: 0
Nylex wrote:
Quote:
Out of interest, though, why are you converting C and PHP programs to Bash?
In order to convert formatted text files, e.g. guttenberg.org, into well formatted XML, Kindle or HTML on the fly. Currently they have to be down loaded converted with an app and uploaded to the server.

Thanks to the others for the many online references.

Like the commuter from India, I do a lot of traveling where online is not available.

Frank
 
  


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
Need variable for yesterday's date stefaandk Programming 8 01-28-2007 10:50 PM
date variable user52 Linux - Newbie 2 11-28-2006 08:48 AM
Find variable in template file replace w/date+ and save as jmanjohn61 Linux - General 14 12-13-2004 06:49 AM
Setting environment variable to current date/time nafan Programming 1 08-23-2004 09:04 PM
loading data from a flat file with a date and time having a different format spyghost Programming 2 11-02-2003 04:40 PM


All times are GMT -5. The time now is 10:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration