- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting question (exiting a while loop)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 09:59 AM
09-05-2000 09:59 AM
Scripting question (exiting a while loop)
I'm writing a while loop that reads input from a file. I then run some tests on the data. If the tests pass then it should continue, but if they fail then I want to move to the next record. I've tried putting a "done" statement in my "then" statement, but apparently it doesn't like that (I get an unexpected done error). Any thoughts?
Thanks ,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:02 AM
09-05-2000 10:02 AM
Re: Scripting question (exiting a while loop)
Use the "break" keyword....
do a man on sh-posix for more details.
cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:11 AM
09-05-2000 10:11 AM
Re: Scripting question (exiting a while loop)
Use 'break' to exit the loop, 'continue' to go back to the start.
Both commands have a numeric argument which indicates which level of loop (for loops within loops).
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:11 AM
09-05-2000 10:11 AM
Re: Scripting question (exiting a while loop)
Use 'break' to exit the loop, 'continue' to go back to the start.
Both commands have a numeric argument which indicates which level of loop (for loops within loops).
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:12 AM
09-05-2000 10:12 AM
Re: Scripting question (exiting a while loop)
do (command)
done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:18 AM
09-05-2000 10:18 AM
Re: Scripting question (exiting a while loop)
YOu will have to use in your while loop with if statements the words break or continue
example of while syntax:
while true
do
echo Enter filename
read FILE
if [ "$FILE" = "" ]
then
break
fi
echo "Edit : " $FILE " ?"
read AA
if [ "$AA" = "" -o "$AA" = no ]
then
continue
else
rm $FILE
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:36 AM
09-05-2000 10:36 AM
Re: Scripting question (exiting a while loop)
...
Very hard trying to be multitasking, you know being at the phone on rm subject, people calling you from outside and trying to reply all at the same time...
Sorry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:37 AM
09-05-2000 10:37 AM
Re: Scripting question (exiting a while loop)
Ex.
test() {
if (logical test)
then
break
fi
}
#main body
while read xyz
do
test;
done
Any thoughts?
Thanks for the help,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:37 AM
09-05-2000 10:37 AM
Re: Scripting question (exiting a while loop)
Ex.
test() {
if (logical test)
then
break
fi
}
#main body
while read xyz
do
test;
done
Any thoughts?
Thanks for the help,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:38 AM
09-05-2000 10:38 AM
Re: Scripting question (exiting a while loop)
Ex.
test() {
if (logical test)
then
break
fi
}
#main body
while read xyz
do
test;
done
Any thoughts?
Thanks for the help,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:38 AM
09-05-2000 10:38 AM
Re: Scripting question (exiting a while loop)
Ex.
test() {
if (logical test)
then
break
fi
}
#main body
while read xyz
do
test;
done
Any thoughts?
Thanks for the help,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:40 AM
09-05-2000 10:40 AM
Re: Scripting question (exiting a while loop)
If, in your last post, the objective is to exit the function at large, change the break to a return. You will exit the loop and the function at that point.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 10:56 AM
09-05-2000 10:56 AM
Re: Scripting question (exiting a while loop)
1) you have no condition to your while:
while
do
..
then you should put your read in the loop
while..
do
read
your test
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 11:10 AM
09-05-2000 11:10 AM
Re: Scripting question (exiting a while loop)
I wonder if you should not try to use continue!
For continue tells the shel to ignore the remainder of the loop and return to the beginning of your loop.
So you should write somthing like
while..
do
read..
if
then
continue
fi
more treatment
..
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 11:35 AM
09-05-2000 11:35 AM
Re: Scripting question (exiting a while loop)
The break needs to be in the loop. Do something like:
while read X
do
echo "I saw $X"
if [ "$X" = "ok" ]
then
break #...quit reading...exit the loop!
fi
done
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 12:01 PM
09-05-2000 12:01 PM
Re: Scripting question (exiting a while loop)
Steve
# This one works
while read first last loc
do
if [ "$last" = "" ]
then
continue
fi
echo $first $last
done < names
# This one don't
tst() {
if [ "$last" = "" ]
then
continue
fi
}
while read first last loc
do
tst;
echo $first $last
done < names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2000 02:03 PM
09-05-2000 02:03 PM
Re: Scripting question (exiting a while loop)
Your example with a function:-
tst() {
if [ "$last" = "" ]
then return 0
else return 1
fi
}
while read first last loc
do
if tst;
then continue
fi
echo $first $last
done < names