Shell 中断与退出(continue、break、exit)

简介: Shell 中断与退出(continue、break、exit)
  • continue:结束单次循环
# 变量 1-5
for item in {1..5}; do
  # 等于 3 时,跳过继续循环
  [ $item -eq 3 ] && continue
  # 输出
  echo $item
done
echo over
# 输出结果:
1
2
4
5
over
  • break:结束循环体
# 变量 1-5
for item in {1..5}; do
  # 等于 3 时,结束循环
  [ $item -eq 3 ] && break
  # 输出
  echo $item
done
echo over
# 输出结果:
1
2
over
  • exit:退出脚本
# 变量 1-5
for item in {1..5}; do
  # 等于 3 时,退出脚本
  [ $item -eq 3 ] && exit
  # 输出
  echo $item
done
echo over
# 输出结果:
1
2
相关文章
|
3月前
|
人工智能 Shell 程序员
[oeasy]python005_退出游乐场_重启游乐场_系统态shell_应用态_quit
[oeasy]python005_退出游乐场_重启游乐场_系统态shell_应用态_quit
16 0
|
Shell
设置shell脚本执行错误自动退出
设置shell脚本执行错误自动退出
794 0
|
1月前
|
Shell Linux C语言
【Shell 命令集合 系统管理 内置命令】⭐⭐Linux 退出当前的Shell会话 exit命令 使用指南
【Shell 命令集合 系统管理 内置命令】⭐⭐Linux 退出当前的Shell会话 exit命令 使用指南
34 0
|
Shell Linux
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
想过很多朋友有遇到这种情况,就是正在远程使用centos7系统时,一旦让远程虚拟机或服务器断电或强制关机,那么再次重启时就会出现“Entering emergency mode. Exit the shell to continue.”的错误。
9988 0
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
|
4月前
|
Shell Linux
linux|shell编程|shell脚本的一些高级技巧(shell脚本内的括号,中括号,花括号,逻辑判断,脚本优雅退出等等)
linux|shell编程|shell脚本的一些高级技巧(shell脚本内的括号,中括号,花括号,逻辑判断,脚本优雅退出等等)
49 0
|
Shell
Shell内值命令之exit
Shell内值命令之exit
387 0
|
Shell Linux
解决Linux shell中断后服务宕机问题
解决Linux shell终端后服务宕机问题 以gitbook为例,gitbook总是启动后关闭shell服务立马宕掉如何解决呢,我们可以用screen命令开一个子shell,在里面执行启动命令即可 执行如下完这三条命令后,shell终端关闭,服务也不会断掉了
125 0