Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning a values from a file

Status
Not open for further replies.

Rvir

Programmer
May 16, 2007
18
US
I've to assign values to a variable in a shell script from a file . The file looks like this

V1
V2
V3

I've defined a loop in my shell script but i do not know how to assign v1 ,v2 and v3 one at time . Can any one suggest an approach

 
What have you tried so far?

(This sounds a little like a homeword assignment)

 

Here are some hints:

If you need to assign each value in turn and process separate, use a while--read loop.

If you want ALL values in one variable at once, use a combination of assignment and cat command.

[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Try
Code:
#!/bin/ksh 
set -a array $(< /path/to/file)
echo ${array[1]} ${array[2]} ${array[3]}

On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top