4

Bash Case语句的终结符

 3 years ago
source link: https://www.lujun9972.win/blog/2019/07/01/bash-case%E8%AF%AD%E5%8F%A5%E7%9A%84%E7%BB%88%E7%BB%93%E7%AC%A6/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Bash Case语句的终结符

Case分支语句的一般常用格式是这样的:

case $变量名 in
    模式1)
        命令序列1
        ;;
    模式2)
        命令序列2
        ;;
    *)
        默认执行的命令序列
        ;;
esac

但是今天偶尔看到 bash manual 中关于 case 语句的说明中有这么一段:

If the ;; operator is used, no subsequent matches are attempted after the first pattern  match.
Using  ;&  in  place of ;; causes execution to continue with the list associated with the next set of  patterns.
Using  ;;&  in place  of  ;;  causes the shell to test the next pattern list in the statement, if any, and execute any associated list on a successful  match.  

也就是说,case语句的分句终止符不仅仅可以时 ;; 还可以 ;&;;&, 他们的作用分别为:

;;不再进行后续的匹配,直接跳出case语句 ;&不再进行后续的匹配,继续执行后面的case分句 ;;&继续对后面的case分句进行匹配,若能找到匹配项则执行该分句。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK