LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2004, 04:18 AM   #1
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Rep: Reputation: 30
Bash: add date to output line


hey all, i am writing a simple script so i can run to tell me and record the temperature given in /proc/acpi.
i have so far

#!/bin/bash
#
temp='cat /proc/acpi/thermal_zone/THRM/temperature'
thedate= date + "%r" // variable for current time

$temp >> /home/josh/recordtemp // directory to hold results




my issue, is being able to place $thedate on the same line as the temperature. In other words, how can i code this so that :
$temp AND thedate >> /home/josh/recordtemp


any help, much appretiated, thanks!

josh
 
Old 11-09-2004, 04:30 AM   #2
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
Re: Bash: add date to output line

Quote:
Originally posted by blizunt7
#!/bin/bash
#
temp='cat /proc/acpi/thermal_zone/THRM/temperature'
thedate= date + "%r" // variable for current time

$temp >> /home/josh/recordtemp // directory to hold results
Code:
temp='cat /proc/acpi/thermal_zone/THRM/temperature'
thedate=`date +"%r"`      // variable for current time

echo $temp $thedate >> /home/josh/recordtemp   // directory to hold results

Last edited by shy; 11-09-2004 at 04:31 AM.
 
Old 11-09-2004, 10:06 AM   #3
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
i added :

echo $temp $thedate >> /home/josh/recordtemp

and all it did was echo out what what placed into the variables temp and thedate??? not what i wanted...
 
Old 11-09-2004, 10:21 AM   #4
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
Quote:
Originally posted by blizunt7
not what i wanted...
Well, could you please provide an example of what you wanted?
 
Old 11-09-2004, 10:44 AM   #5
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
hey,

what i am trying to do is print to a file the tempurature given in: /proc/acpi/......
so it will print (in pseudocode):
date Temperature

so i am simple tryin, for example:
$thedate $temp >> /home/josh/recordtemp
to print the date defined above and $temp is given also above, printed on the same line in /recordtemp. I am not sure how to put these two environment variable together??

thanks so much
 
Old 11-09-2004, 10:51 AM   #6
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
actually, i think i may have figured it out.. when i defined both environmental variables, i now put them in single backquotes. What is the difference between single backquote and single quote??
`` and ' '


thanks again
 
Old 11-09-2004, 01:05 PM   #7
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
Quote:
Originally posted by blizunt7
`` and ' '
`command` means "substitute this line with command's output"
'string' means just string
 
Old 11-10-2004, 04:45 AM   #8
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Quote:
Originally posted by blizunt7 so it will print (in pseudocode):
date Temperature
OK. Here it is:
Code:
temp="$(cat /proc/acpi/thermal_zone/THRM/temperature)"
thedate="$(date +"%r")"
echo "$thedate $temp" >> /home/josh/recordtemp
Or, if you want to reevaluate the commands at regular times in the same script:
Code:
temp='cat /proc/acpi/thermal_zone/THRM/temperature)'
thedate='date +"%r"'
echo -n "$($thedate)" >> /home/josh/recordtemp
echo "$($temp)" >> /home/josh/recordtemp
I did not test but it should work (if not, try and use eval).

Yves.
 
  


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
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 02:42 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 08:45 PM
use date as output filename? wijnands Linux - Newbie 1 05-12-2004 04:39 PM
Bash scripting - add a character to a line. welby Programming 1 01-14-2004 11:09 AM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 10:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 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