Setting a local variable's value to the content of a file.

Setting a local variable's value to the content of a file.

Post by Matt Brenna » Sat, 21 Mar 1998 04:00:00



I'm trying to write a script and in it I need to use a local variable that
I define and I need to set the value of this variable to the value of the
first line of a file.

I can get the first line of a file by typing:

head -1 filename

...and  it outputs to my screen the first line of the file.  But how do I
assign that output to the value of a variable?

I've tried things like:

head -1 filename > $variablename

set variablename < head -1 filename

I've also tried this:

export variablename=`head -1 filename`

...but I get a permission denied error and the man pages show nothing for
"export".

None of the above works.  Any ideas?  (BTW - we are running DG/UX on a Data
General AViiON.)

Any help is greatly appreciated!  Thanks!

--
Matt Brennan
SQL*Tools Specialist
GERS Retail Systems
9725-C Scranton Road
San Diego, California 92121
1-800-854-2263

 
 
 

Setting a local variable's value to the content of a file.

Post by Sherwin Anthony Sequei » Sun, 22 Mar 1998 04:00:00




Quote:> I'm trying to write a script and in it I need to use a local variable that
> I define and I need to set the value of this variable to the value of the
> first line of a file.

> I can get the first line of a file by typing:

> head -1 filename

> ...and  it outputs to my screen the first line of the file.  But how do I
> assign that output to the value of a variable?

[snip]

try:

        export variable=$( head -1 filename )

        OR

        export variable=`head -1 filename`

Quote:> Any help is greatly appreciated!  Thanks!

        HTH

Tony

 
 
 

1. how to parse 'variable=value' format from file

hi,
    i am new to shell scripting.  i hope somebody can help me.  i have
this file that contains a list of values in 'variable=value' format.
i want to parse the list contained in the file and display them.  for
example:
    value of variable1 is 'value1'
    value of variable2 is 'value2'
    ...
any advice?  thank you very much

2. Quake 3

3. how can I create a single variable that consists of 2 variables' values

4. Hack Alert

5. Stripping out value from file, value is a variable though.

6. help! conflicts: apache 1.2 and 1.3

7. How do you set a variable's initial value in Bourne or tcsh shells?

8. sound with CMI8330 audio

9. file contents into variable, or global variable from shell script

10. Set sh-variables out of content of a file

11. Can't use RH 9 cups: UnboundLocalError: local variable 'which'

12. Echoing value of variable when value contains "$"

13. Better Way to Get Value of Value of Variable in Bourne shell?