- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: break out of 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
Discussions
Discussions
Forums
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
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
тАО04-20-2007 01:00 AM
тАО04-20-2007 01:00 AM
I am having sytax difficulty breaking out of a loop:
while read FILES
do
if [ -f archive.gz ] ; then
break
else
for list in `ls $FILES`
do
cat $list >> $outfile
done
done < $dirlist
so funny as it seems dirlist contains a list of directories however if that directory has already been processed I want the script skip cat'ing all files in the dir and continue with the next directory in $dirlist however all that happens is the scripts exits
I am obviously not using break correctly, any idea's?
Thanks
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2007 01:09 AM
тАО04-20-2007 01:09 AM
Re: break out of loop
Still I thought break would have the same effect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2007 01:14 AM
тАО04-20-2007 01:14 AM
Solutionwhile read FILES
do
if [ ! -f archive.gz ]
then
for list in `ls $FILES`
do
cat $list >> $outfile
done
done < $dirlist
As for the break command, it's doing exactly what it's supposed to do. Per the sh-posix(1) man page:
% break [n] Exit from the enclosing for, select, until, or while loop, if any. If n is specified, exit from n levels.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2007 01:21 AM
тАО04-20-2007 01:21 AM
Re: break out of loop
depends on your programming logic.
While "break" would leave the loop immediately
(note, that although you cannot specify labels like in Perl to distinguish which of several nested loops to exit, you may give braek an optional decimal that specifies the n'th level)
a "continue" would simply skip all the remaining execution block of a loop to enter the next iteration.
(needless to mention that "continue" also honours an optional loop level argument like "break").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2007 02:59 AM
тАО04-20-2007 02:59 AM
Re: break out of loop
that has cleared some questions.