shell中的break和exit的区别

2025-05-23 09:26:57
推荐回答(1个)
回答(1):

bash shell script (bash脚本)中,break是退出一层循环,break 2是退出2层循环(当有相互嵌套时),....

break: break [n]
Exit for, while, or until loops.

Exit a FOR, WHILE or UNTIL loop. If N is specified, break N enclosing
loops.

Exit Status:
The exit status is 0 unless N is not greater than or equal to 1.
脚本中的exit的作用是整个脚本退出了,逻辑上exit之后的命令不再运行。