- Linux Admin Tutorial
- Home
- CentOS Overview
- Basic CentOS Linux Commands
- File / Folder Management
- User Management
- Quota Management
- Systemd Services Start and Stop
- Resource Mgmt with systemctl
- Resource Mgmt with crgoups
- Process Management
- Firewall Setup
- Configure PHP in CentOS Linux
- Set Up Python with CentOS Linux
- Configure Ruby on CentOS Linux
- Set Up Perl for CentOS Linux
- Install and Configure Open LDAP
- Create SSL Certificates
- Install Apache Web Server CentOS 7
- MySQL Setup On CentOS 7
- Set Up Postfix MTA and IMAP/POP3
- Install Anonymous FTP
- Remote Management
- Traffic Monitoring in CentOS
- Log Management
- Backup and Recovery
- System Updates
- Shell Scripting
- Package Management
- Volume Management
- Linux Admin Useful Resources
- Linux Admin - Quick Guide
- Linux Admin - Useful Resources
- Linux Admin - Discussion
Linux Admin - Loop Control
Sometimes (a lot times actually) we will either want to skip loop iteration operation or break out of a loop prior to completion. These operations are performed with the following verbs: continue and break.
continue
#!/bin/bash myFile = "myLines.txt" while read -a FILENAME; do if [ `echo $FILENAME | grep 004` ]; then continue fi echo $FILENAME done < $myFile
The snippet above will skip the 4th line of the text file, then continue script execution.
line001 line002 line003 line005 line006 line007 line008 line009
break
Break will stop the loop in its entirety rather than skip a single iteration when a condition is met.
#!/bin/bash myFile = "myLines.txt" while read -a FILENAME; do if [ `echo $FILENAME | grep 004` ]; then break fi echo $FILENAME done < $myFile
The above script produces the following output.
line001 line002 line003
linux_admin_shell_scripting.htm
Advertisements