Advertisement
v1ral_ITS

loop example with condition continue until main defined cond

Aug 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.59 KB | None | 0 0
  1. for I in 1 2 3 4 5
  2. do
  3.     statements1 #Executed for all values of ''I'', up to a disaster-condition if any.
  4.     statements2
  5.     if (condition)
  6.     then continue #Go to next iteration of I in the loop and skip
  7.     statements3
  8. fi
  9.  
  10. Following shell script will go though all files stored in /etc directory. The for loop will be abandon when /etc/resolv.conf file found.
  11.  
  12. #!/bin/bash
  13. for file in /etc/*
  14. do
  15.     if [ "${file}" == "/etc/resolv.conf" ]
  16.     then
  17.         countNameservers=$(grep -c nameserver /etc/resolv.conf)
  18.         echo "Total  ${countNameservers} nameservers defined in ${file}"
  19.         break
  20.     fi
  21. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement