2

I want to know if there is a way to leave imbricated for loop:

check_mac_address() {
    local mac="$1"
    for wunit in `get_wunit`; do
        for iuc in `get_iuc`; do            
            for assoc_mac in `get_iuc $wunit $iuc`;do
                if [ "$assoc_mac" = "$mac"]; then 
                    local int_type="WF" 
                    break #---> break from all loop  
                else
                    int_type="ETH"
                    break #---> break from all loop  
                fi 
            done
        done
    done
}

any help is appreciated

stack_A
  • 713
  • 4
  • 13
  • 21

2 Answers2

4

break takes a parameter which specifies how many levels of surrounding loops to break; in your case I believe it would be 3:

http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins

Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
2

From http://tldp.org/LDP/abs/html/loopcontrol.html

A plain break terminates only the innermost loop in which it is embedded, but a break N breaks out of N levels of loop.

So in your case you to break from all three loops you can do

break 3
user000001
  • 32,226
  • 12
  • 81
  • 108
  • 1
    A link to the bash reference manual or the appropriate POSIX specification is much more useful than one to the TLDP bash guide. – Etan Reisner May 04 '15 at 13:16