Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does -ex option used in bash | #!/bin/bash -ex mean

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 
like image 216
user128364 Avatar asked Jul 13 '16 05:07

user128364


People also ask

What does option do in Bash?

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.

What is option in bin Bash?

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.

What does option mean in Linux?

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.

What is option shell?

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.


1 Answers

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.

like image 166
Merry Avatar answered Oct 02 '22 06:10

Merry