LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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



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

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

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