bash - 从嵌套的 for 循环中跳出

标签 bash shell ash

我想知道是否有办法让 for 循环层叠起来:

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
}

感谢任何帮助

最佳答案

break 接受一个参数,该参数指定要中断多少层周围循环;在你的情况下,我相信它是 3:

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

关于bash - 从嵌套的 for 循环中跳出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30030523/

相关文章:

macos - .bash_profile 和脚本作为符号链接(symbolic link)

linux - 如何从 MAKEFILE 中的字符串列表中提取具有特定模式的字符串?

linux - 如何获取使用 nohup 运行的程序列表

linux - 如何使用 Linux (Bash) 在目录内移动文件

linux - 如何将一些行移动到文件的顶部?

linux - 如何将所有命令参数放在一个变量中

bash - 如何用空格分隔 "sentence"中的单词?

linux - 从 *.txt 搜索并将文件复制到新目录

linux - echo 不在 bash 中打印变量

linux - 如何将文本文件中杂乱的内容排序成单列