Bash trace mode (bash -x) in the shebang

bash

Solution

The shebang-line mechanism only parses the first space and passes the rest of the line as one single argument to the executable, so writing

#!/usr/bin/env bash -x

is like calling

$ /usr/bin/env "bash -x"

on the command line.

There is no executable called `"bash -x"` (with a space in the command name), so this fails.

Problem

How come this style works: ``` #!/bin/bash -x #... ``` But this doesn't? ``` #!/usr/bin/env bash -x #... ``` It gives me a not found error. Trace mode needs to be set later as `set -x`? Please note that I can use `#!/usr/bin/env bash`.

Original source