05-21-2005
read inside a while loop
Hi all,
In a while loop, like below...
while read line
do
read choice
case $choice in
1)
echo "xxx"
esac
done < file
why I can't run the read choice????
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all
Does anyone have a script that will allow me to stop inside a while read loop.
I want to pause the loop until a enter is pressed.
e.g.
While read line
do
echo something
if LINECOUNT > 40
then
read ENTER?"PRESS ENTER TO CONT..."
... (3 Replies)
Discussion started by: jhansrod
3 Replies
2. Shell Programming and Scripting
Hi,
'read' command is not working inside the while loop, How can I solve this?
Rgds,
Sharif. (2 Replies)
Discussion started by: sharif
2 Replies
3. Shell Programming and Scripting
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
4. Shell Programming and Scripting
Hi all
Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies
5. Shell Programming and Scripting
Hi,
I am reading file records inside a while loop,
and want to update the record when certain condition is met.
How can I update a file while being read?
I want to avoid using temporary files, copy, rename, ...
while IFS=',' read -r f1 f2
do
function(f1,f2)
if
then
<add... (1 Reply)
Discussion started by: ysrini
1 Replies
6. Shell Programming and Scripting
Hello,
I have a set of files Xfile0001 - Xfile0021, and the content of this files (one at a time) needs to be printed between some line (lines start with word "Generated") that I am extracting from another file called file7.txt and all the output goes into output.txt. First I tried creating a for... (5 Replies)
Discussion started by: jaldo0805
5 Replies
7. UNIX for Dummies Questions & Answers
I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off....
I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies
8. Shell Programming and Scripting
Hi there guys!
I was trying to do:
while read line; do
if ; then
read -p "Press Enter to continue..."
cont=0
fi
echo $line
let cont++
done < file.txt
However, I have read that the read -p would not work in a while loop...
I was wondering if there is any other way to... (2 Replies)
Discussion started by: rplae
2 Replies
9. Shell Programming and Scripting
Hi,
This query is a part of a much more lengthy script.
I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to.
Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies
10. Shell Programming and Scripting
Hi everybody,
I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o
My code:
#!/bin/sh
set -e
set -u
export IFS=
optl="Optl"
LOCSTORCLI="/opt/lsi/storcli/storcli"
($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
LEARN ABOUT ULTRIX
getsvc
getsvc(3) Library Functions Manual getsvc(3)
Name
getsvc - get a pointer to the svcinfo structure
Syntax
#include <sys/svcinfo.h>
struct svcinfo *getsvc()
Description
The call retrieves information from the system about the structure by returning a pointer to the structure. This structure is initialized
the first time a call is made. The contents of the file are parsed and stored in the structure. If the file is modified, the contents of
this structure will be updated upon the next call.
The file contains the names of the databases that can be served by YP, BIND, or local files and the name service selection for each data-
base. It also has settings for four security parameters. The database service selection and security parameters are stored in the struc-
ture.
The following structure exists in the file:
#define SVC_DATABASES 20
#define SVC_PATHSIZE 8
struct svcinfo {
int svcdate; /* Last mod date of /etc/svc.conf */
int svcpath[SVC_DATABASES][SVC_PATHSIZE]; /* indexed by
databases and choice 0=first choice
1=second choice, etc value stored is
source */
struct {
int passlenmin;
int passlenmax;
int softexp;
int seclevel;
} svcauth;
};
The field contains the date that the file was last modified. The array contains the name service choices for each database. The structure
contains the values for the four security parameters: password length minimum (passlenmin), password length maximum (passlenmax), soft
expiration date of a password (softexp), and security mode of a system (seclevel).
Examples
The following programming example shows how to use the call to use the information in the structure to process specific host information.
#include <sys/svcinfo.h>
struct svcinfo *svcinfo;
if ((svcinfo = getsvc()) != NULL)
for (i=0; (j = svcinfo->svcpath[SVC_HOSTS][i]) != SVC_LAST; i++)
switch(j) {
case SVC_BIND:
/* process BIND hosts */
case SVC_YP:
/* process YP hosts */
case SVC_LOCAL:
/* process LOCAL hosts */
}
Files
See Also
svc.conf(5), svcsetup(8)
getsvc(3)