3

I'm using env in a shell script like so:

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

Mainly so my scripts are more portable. Anyway, i noticed that adding arguments to application that use env doesn't always work...

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

yield

/usr/bin/env: ‘bash -x’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

I'm unsure on the correct formatting for the arguments. I checked the man page and i didn't see anything that would help either (afaik).

1 Answers1

3

Seems using the -S flag on env, like so:

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

works.

It is interesting to note that, for some reasons, it is not stated in the man page, though, it is shown in the --help output.

Probably has to do with the fact that env only started to have the -S flag when coreutils got updated (to 8.30). I'm guessing most man page aren't updated and still have information from before 8.30 (eg: 8.28 didn't have the -S flag).

reference:

https://jhermann.github.io/blog/linux/know-how/2020/02/28/env_with_arguments.html https://linux.die.net/man/1/env