Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

UNIX Script Help

Posted on 2014-01-30
8
Medium Priority
?
203 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 1600 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 400 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
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…

721 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