Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

UNIX Script Help

Hello,

I need some help in writing a shell script, So if i have

echo "Enter the disks name: "
read DISK

Then what ever disk name I type in is assigned to the variable DISK.

But if I have a file, which has disks
#cat file
hdisk1
hdisk2
hdisk3
hdisk4

So how do i script to "read" the disks in a file...??
0
aanya247
Asked:
aanya247
2 Solutions
 
ozoCommented:
cat > Q_28352688.sh << END
echo "Enter the disks name: "
read DISK
echo $DISK
END

sh Q_28352688.sh < file

for D in `cat file` ; do echo $D | sh Q_28352688.sh ; done
0
 
aanya247Author Commented:
Thanks OZO for your response....

I didnot quite understand, What is Q_28352688.sh, I only have one file 'file' in which i have disks. I am sorry I am still in a learning phase..
0
 
Dan CraciunIT ConsultantCommented:
It's called a here document and basically inserts into Q_28352688.sh whatever follows until it reaches END.

HTH,
Dan
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ozoCommented:
I don't know the name of your shell script or what else you have in it,
so for illustrative purposes, I created one in order to demonstrate some ways to read DISK from file
0
 
TintinCommented:
Easier to do

cat file | xargs yourscript.sh
0
 
ozoCommented:
xargs yourscript.sh
might work with
DISK=$1
but not with
read DISK
0
 
SurranoSystem EngineerCommented:
the `cat ...` method may fail with large lists (something like 2M which is not *that* much) since a command line can't have arbitrary length.

Strange that nobody came up with while read (please don't reopen the question):

cat file | while read DISK; do
  echo $DISK
done

Open in new window

0
 
aanya247Author Commented:
Thank you...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now