LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-13-2008, 03:33 AM   #1
PatrickBecks
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Rep: Reputation: 0
Getting a variable from a text-file (bash)


Hello y'all,

I have a text-file which contains a number (ex: 32)
I want to do some calculations with the content of this text-file.

ex: 3200 - "number in the text-file" (so 3200 - 32)

Now, my idea is to MAKE A VARIABLE (var) from the content of the text-file so that i can do this with a bash-script:

#!/bin/sh
pc 3200 - $var > outcome.txt
exit


(pc = the Python Calculator, works great by the way!)

What i can't manage is to make a variable from the content of the text-file .

Any tips? ideas? solutions?

Greetings from the Netherlands

Patrick
 
Old 02-13-2008, 04:12 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,148

Rep: Reputation: 236Reputation: 236Reputation: 236
var=$(cat textfilename)
 
Old 02-13-2008, 08:38 PM   #3
JWPurple
Member
 
Registered: Feb 2008
Posts: 67

Rep: Reputation: 17
Quote:
Originally Posted by Guttorm View Post
var=$(cat textfilename)
or even more efficient and concise:
Code:
var=$(<textfilename)
 
Old 02-14-2008, 03:14 AM   #4
PatrickBecks
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
var=$(<textfilename)

var=$(<textfilename) doesn't work..

ex: var1=$(cat /home/patrick/scripts/totaldownload.txt) WORKS!

ex: var1=$(</home/patrick/scripts/totaldownload.txt) doesn't work.
 
Old 02-14-2008, 08:52 PM   #5
JWPurple
Member
 
Registered: Feb 2008
Posts: 67

Rep: Reputation: 17
Quote:
Originally Posted by PatrickBecks View Post
var=$(<textfilename) doesn't work..

ex: var1=$(cat /home/patrick/scripts/totaldownload.txt) WORKS!

ex: var1=$(</home/patrick/scripts/totaldownload.txt) doesn't work.
Code:
wake@dog:~> echo hello >tmp.txt
wake@dog:~> temp=$(<tmp.txt)
wake@dog:~> echo $temp
hello
wake@dog:~>
Works for me!
 
  


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 in variable length text records lynx81191 Programming 4 11-17-2007 08:53 PM
Bash store last line from displayed text output in a variable carl0ski Programming 1 01-16-2007 03:38 AM
Variable in Bash get from other file?? helptonewbie Programming 4 08-21-2006 07:51 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
how to cat a text file and save it as a variable mrobertson Programming 37 07-05-2005 08:20 AM


All times are GMT -5. The time now is 01:10 PM.

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