Solved

UNIX Script Help

Posted on 2014-01-30
8
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

630 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