linux - bash 中使用的 -ex 选项是什么 | #!/bin/bash -ex 意思

标签 linux bash shell scripting

我们使用下面的脚本作为 EC2 实例的用户数据。我不明白 -ex 选项的用途是什么?

#!/bin/bash -ex

yum update -y
yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"
service httpd start
chkconfig httpd on

最佳答案

根据Add tack e x on your bash shebang | #!/bin/bash -ex

Bash scripts can use various options on the shebang (#!/bin/bash). A more common one is: ‘#!/bin/bash -ex’.

-e Exit immediately if a command exits with a non-zero status.
-x Print commands and their arguments as they are executed.

In short, adding -ex to your #!/bin/bash will give verbose output and also will abort your script immediately if part of the script fails.

关于linux - bash 中使用的 -ex 选项是什么 | #!/bin/bash -ex 意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342992/

相关文章:

linux - 直接从 linux 内核访问系统性能数据

linux - 从包含 ANSI 转义属性的 gitlab-runner 输出中解析标记值

bash - 将 bash 变量传递给 rollup.js

linux - 如何增加 Ubuntu 的 inode 限制?

java - java 的 strace 或 procmon 等效项

linux - 为什么系统调用失败?

linux - 在 shell 脚本中运行 aapt 以转储目录下所有 apk 文件的权限?

ruby - 如何包含使用 FileUtils#sh 执行命令的管道?

linux - 贝加尔湖需要特定文件夹的写入权限

Bash PDF 合并丢失文件