LinuxQuestions.org
Help answer threads with 0 replies.
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-15-2004, 06:51 AM   #1
marri
Member
 
Registered: May 2004
Posts: 38

Rep: Reputation: 15
reading file, bash script


hi
I'm writing a script that should read a number from a file and store it in a variable. I just can't find out how to read from a file and store the value read in a variable within the script.
Can anybody help here??
regards
 
Old 11-15-2004, 07:20 AM   #2
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
try
Code:
var=$(cat /some/file)
 
Old 11-15-2004, 08:59 AM   #3
marri
Member
 
Registered: May 2004
Posts: 38

Original Poster
Rep: Reputation: 15
thanks alot, that was what I was looking for.
regards
 
Old 11-15-2004, 09:13 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
And a faster equivalent:
Code:
var=$(</some/file)
 
  


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 script – reading and writing variables to a separate file morrolan Programming 10 09-20-2005 07:45 AM
Reading a conf file from a BASH script dinolinux Programming 5 08-03-2005 04:18 AM
bash; reading values from a file km4hr Programming 16 07-28-2005 02:07 PM
Need help reading text file in bash script scilec Programming 3 11-25-2004 06:44 PM
Bash script - reading from text file twantrd Programming 4 11-24-2004 12:38 AM

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

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