You are not logged in.

#1 2007-03-26 22:17:33

Aziere
Member
Registered: 2007-03-16
Posts: 23

(Bash) How to set a variable with text from a file? [SOLVED]

I'm having a little problem.
I have textfile with a single line of text. What I want to do is set a variable with that line of text. How do I go about doing that?

A simple var="text" wont work in this case, since the text in the file changes with another script of mine.

Thanks in advance.

Last edited by Aziere (2007-03-27 09:07:03)

Offline

#2 2007-03-26 23:37:12

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: (Bash) How to set a variable with text from a file? [SOLVED]

var="`cat file`"

Offline

#3 2007-03-27 03:43:06

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: (Bash) How to set a variable with text from a file? [SOLVED]

Or var=$( cat file ), if you like.

Offline

#4 2007-03-27 05:54:40

SiD
Member
From: Germany
Registered: 2006-09-21
Posts: 729

Re: (Bash) How to set a variable with text from a file? [SOLVED]

if you have a file with more than one line but you only want the first line you could use 'head'

VAR=`head -n 1 file`

Last edited by SiD (2007-03-27 05:58:33)

Offline

Board footer

Powered by FluxBB