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 - 允许 DOCKER-USER 链中的某些 IP 用于入站流量,拒绝所有其余 IP

linux - Freescale (NXP) S32V234板,没有提供ADC驱动。

linux - bash 中 * 与 * 的连接

java - SWT 浏览器 - 禁用垂直滚动我如何隐藏它?

windows - 如何让我的文件关联在单个程序实例中打开多个文件?

Linux - 编辑剪贴板内容的脚本

linux - 在 Ubuntu 12.04.1 下构建 cross-gcc 4.7.2

Bash 通配符的使用

Linux - 如何在文件中搜索单词并打印它们出现的次数?