linux - shell脚本停止错误

标签 linux shell

我有以下脚本,如果第 x 行遇到错误,我希望脚本在第 x 行停止执行,我该怎么做?

pvcreate /dev/$1
vgextend VolGroup00 /dev/$1
lvextend --size +$2 /dev/VolGroup00/LogVol00
resize2fs /dev/VolGroup00/LogVol00

最佳答案

将以下内容添加到顶部。

set -e

执行该行后,如果任何行返回错误代码,shell 将退出。 set +e 将再次关闭此功能(即切换回继续,而不管任何错误返回代码)。

参见 http://www.davidpashley.com/articles/writing-robust-shell-scripts.html了解更多详情。

关于linux - shell脚本停止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5976361/

相关文章:

linux - 如何在子shell中找出父shell的用户?

java - 如何优化 Tomcat 上运行的 Java 进程

linux - 如何在命令行上设置 Log4perl 日志级别?

Xcode 和 Git 在 MacOSX Mountain Lion 上的安装

Linux shell : sed replace value in xml

linux - grep 函数是否检测制表符分隔符?

php - 在linux上添加bash脚本来创建用户

linux - linux 中的部分目录列表

linux - 如何将 uniq 命令的输出分配给 shell 脚本中的变量

linux - 无法通过 hadoop Web 控制台在 hadoop 上创建目录