Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash trace mode (bash -x) in the shebang

Tags:

bash

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.

like image 954
CMCDragonkai Avatar asked Jun 04 '14 08:06

CMCDragonkai


2 Answers

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.

like image 142
Alfe Avatar answered Oct 15 '22 23:10

Alfe


You can always use:

#!/usr/bin/env bash
set -x
like image 24
Juan Diego Godoy Robles Avatar answered Oct 16 '22 00:10

Juan Diego Godoy Robles