6

In the repository on GitHub of Tribler, I see a file with the interpreter: #!/bin/sh -xe.

On Mac and Linux man sh redirects to BASH(1) (same as man bash).

In this man file, under the section:

OPTIONS

,there is no mention of an option -x , nor an option -e.

What is the meaning of the interpreter #!/bin/sh -xe ?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
azbc
  • 399
  • 1
  • 5
  • 12
  • 1
    for `-e` there's [this answer](https://stackoverflow.com/a/34097445/9858236) – alegria Dec 01 '18 at 20:40
  • 1
    The first line in the `OPTIONS` session says that you can use all the options (including `-x` and `-e`) documented under the `set` built-in when starting `bash`. The flags that follow are just *additional* flags.= – chepner Dec 01 '18 at 21:08

2 Answers2

9

I found this:

man sh:

-x xtrace        Write each command to standard error (preceded by
                            a ‘+ ’) before it is executed.  Useful for debug‐
                            ging.


-e errexit       If not interactive, exit immediately if any
                            untested command fails.  The exit status of a com‐
                            mand is considered to be explicitly tested if the
                            command is used to control an if, elif, while, or
                            until; or if the command is the left hand operand
                            of an “&&” or “||” operator.

It seems these are just error control options that make sure nothing worse happens if a command fails.

Caleb H.
  • 1,657
  • 1
  • 10
  • 31
  • Note that using `-e` can be **very** counterproductive, creating bugs where none existed; see the exercises in [BashFAQ #105](http://mywiki.wooledge.org/BashFAQ/105#Exercises), and the list of incompatibilities between how different shells handle this flag at https://www.in-ulm.de/~mascheck/various/set-e/ – Charles Duffy Dec 01 '18 at 20:50
1

Per man page: read more

The -a, -b, -C, -e, -f, -m, -n, -o option, -u, -v, and -x options are described as part of the set utility in Special Built-In Utilities. The option letters derived from the set special built-in shall also be accepted with a leading plus sign ( '+' ) instead of a leading hyphen (meaning the reverse case of the option as described in this volume of IEEE Std 1003.1-2001).

when you read set man pages you get:

-x The shell shall write to standard error a trace for each command after it expands the command and before it executes it. It is unspecified whether the command that turns tracing off is traced.

and

-e When this option is on, if a simple command fails for any of the reasons listed in Consequences of Shell Errors or returns an exit status value >0, and is not part of the compound list following a while, until, or if keyword, and is not a part of an AND or OR list, and is not a pipeline preceded by the ! reserved word, then the shell shall immediately exit.