Nested loops

Nested loops means loops inside loops. Check out the following example:

#!/bin/bash 
for (( v1 = 1; v1 <= 3; v1++ )) 
do 
   echo "First loop $v1:" 
   for (( v2 = 1; v2 <= 3; v2++ )) 
   do 
         echo " Second loop: $v2" 
   done 
done 

The first loop hits first, then the second loop, and this happens three times.

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.