From bash manual about shebang
Most versions of Unix make this a part of the operating system’s command execution mechanism. If the first line of a script begins with the two characters‘ #!’, the remainder of the line specifies an interpreter for the program. Thus, you can specify Bash, awk, Perl, or some other interpreter and write the rest of the script file in that language.
The arguments to the interpreter consist of a single optional argument following the interpreter name on the first line of the script file, followed by the name of the script file, followed by the rest of the arguments. Bash will perform this action on operating systems that do not handle it themselves. Note that some older versions of Unix limit the interpreter name and argument to a maximum of 32 characters.
Does "a optional argument" mean an argument to an option, or an argument which may be there or might not be?
Why "a single optional argument"? does it not allow multiple "optional arguments"?
If a script looks like
#! /path/to/interpreter --opt1 opt1-arg --opt2 opt2-arg --opt3 nonopt-arg1 nonopt-arg2
...
when I run the script in bash as
$ myscript arg1 arg2 arg3
what is the actual command being executed in bash? Is it
$ /path/to/interpreter --opt1 opt1-arg --opt2 opt2-arg --opt3 nonopt-arg1 nonopt-arg2 myscript arg1 arg2 arg3
Thanks.
#! /usr/bin/env interpreter
, can there be more afterwards? not even an option? – Tim Aug 20 '17 at 17:56interpreter
plus whatever comes after that will be passed toenv
as a single argument; try it with#!/usr/bin/env echo Test
—env
ends up trying to run a command calledecho Test
(all together) and failing. – Stephen Kitt Aug 20 '17 at 20:33