Bash trace mode (Bash -x) in shebang

How this style works:

#!/bin/bash -x
#...

But is that not so?

#!/usr/bin/env bash -x
#...

This gives me an error not found. Trace mode should be set later how set -x?

Please note that I can use #!/usr/bin/env bash.

+4
source share
2 answers

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

#!/usr/bin/env bash -x

looks like a challenge

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

on the command line.

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

+7
source

You can always use:

#!/usr/bin/env bash
set -x
+6
source

Source: https://habr.com/ru/post/1543176/


All Articles