# reading a file into a varable...

**URL:** <https://community.unix.com/t/reading-a-file-into-a-varable/164222>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [August 14, 2006, 6:34am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222 "2006-08-14T06:34:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![B14speedfreak](https://community.unix.com/letter_avatar/b14speedfreak/32/5_5575768a8748004e209b776fc1b2916d.png) [@B14speedfreak](https://community.unix.com/u/B14speedfreak)\
**Post date:** [August 14, 2006, 6:34am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222/1 "2006-08-14T06:34:41Z")

</div>

Hi all,

I have had a hunt round the net (and the forum (more importantly)) but carn't just see anything that helps. Does anyone care to put me out of my missery and tell me how to read a file into a variable?

thanks,

B14... aka... Marky Mark...

---

<div class="post-metadata">

**Author:** ![apoorvasharma80](https://community.unix.com/letter_avatar/apoorvasharma80/32/5_5575768a8748004e209b776fc1b2916d.png) [@apoorvasharma80](https://community.unix.com/u/apoorvasharma80)\
**Post date:** [August 14, 2006, 6:45am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222/2 "2006-08-14T06:45:33Z")

</div>

try this....

var="`cat file`"

But what do you want to achive through this??

regards  
Apoorva kumar

---

<div class="post-metadata">

**Author:** ![B14speedfreak](https://community.unix.com/letter_avatar/b14speedfreak/32/5_5575768a8748004e209b776fc1b2916d.png) [@B14speedfreak](https://community.unix.com/u/B14speedfreak)\
**Post date:** [August 14, 2006, 6:47am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222/3 "2006-08-14T06:47:01Z")

</div>

well its pretty simple really to be honest. I have a couple of SQL scripts that output some numbers to file, I just want to read them into my script so that I can compare them.

Thanks I will try this out,

Mark.

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [August 14, 2006, 6:50am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222/4 "2006-08-14T06:50:48Z")

</div>

You want to read the entire file into a single variable? At one shot? Dunno if you can do that and keep it readable by anything else... To read the file a line at a time, you can see [this](http://www.unix.com/showthread.php?t=18009) thread.

---

<div class="post-metadata">

**Author:** ![B14speedfreak](https://community.unix.com/letter_avatar/b14speedfreak/32/5_5575768a8748004e209b776fc1b2916d.png) [@B14speedfreak](https://community.unix.com/u/B14speedfreak)\
**Post date:** [August 14, 2006, 6:54am UTC](https://community.unix.com/t/reading-a-file-into-a-varable/164222/5 "2006-08-14T06:54:13Z")

</div>

Well the above does work (under Solaris 5.8) but you see, the files that I am reading are only contain 1 set of numbers (eg could be 1, it could be 14,0954) so I just wanted to read them into a variable and use the numbers in another script.

Thanks for the replies though,

Mark.
