I have copied a shell script and it is pretty much simple but on the first line with shebang, the -xe
flag is specified.
#!/bin/bash -xe
Can anyone explain what does it do? I have searched but could not find any helping material.
This is adding shell options to the shebang:
-x
, -o xtrace
: Trace display executed statements.-e
, -o errexit
: Exit on error, but inconsistently for legacy POSIX compliance.#!/bin/bash -xe
This shebang setting combines two discouraged bad practices with their own set of issues:
bash script_name
, rather than making the script file executable, and invoking ./script_name
.set -x
, or preferably use their more straightforward long name (example: set -o xtrace
instead of set -x
).-e
option or set -o errexit
which is only there for legacy POSIX compliance, but acts so inconsistently in different situations; that it causes more bugs than it avoids.Here are some references about those set -e
, set -o errexit
quirks and issues: