We are using the script below as user data for EC2 instances. I don't understand what is -ex
option is being used for?
#!/bin/bash -ex yum update -y yum groupinstall -y "Web Server" "MySQL Database" "PHP Support" service httpd start chkconfig httpd on
Bash Shell -x Option. Invoking a Bash shell with the -x option causes each shell command to be printed before it is executed. This is especially useful for diagnosing problems with installation shell scripts.
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.
An option, also referred to as a flag or a switch, is a single-letter or full word that modifies the behavior of a command in some predetermined way. A command is an instruction telling a computer to do something, usually to launch a program.
Shell Scripting getopts options The getopts options are used in shell scripts to parse arguments passed to them. When arguments are passed on the command line, getopts parse those arguments instead of command lines. Options are written starting with a hyphen (-), followed by the letter.
According to 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With