Solved

UNIX Script Help

Posted on 2014-01-30
8
194 Views
Last Modified: 2014-02-04
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
Comment
Question by:aanya247
8 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 39822219
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
 

Author Comment

by:aanya247
ID: 39822382
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
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 100 total points
ID: 39822420
It's called a here document and basically inserts into Q_28352688.sh whatever follows until it reaches END.

HTH,
Dan
0
 
LVL 84

Expert Comment

by:ozo
ID: 39822442
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 48

Expert Comment

by:Tintin
ID: 39822597
Easier to do

cat file | xargs yourscript.sh
0
 
LVL 84

Expert Comment

by:ozo
ID: 39822627
xargs yourscript.sh
might work with
DISK=$1
but not with
read DISK
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39831906
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
 

Author Comment

by:aanya247
ID: 39833155
Thank you...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video discusses moving either the default database or any database to a new volume.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now