3 ms·
Here is a use case not involving the motivation to pass canned options passed to the script. Suppose that the interpreter is such that the script name must be
by kazinator 4y ago
Here is a use case not involving the motivation to pass canned options passed to the script.
Suppose that the interpreter is such that the script name must be passed as an option. For instance, Awk implementations are like this:
awk -f <script>
The problem is that this kind of option is allowed to be followed by more options.
awk -f <script> -Z # error under GNU awk: -Z is an invalid option
See where this is headed? If we have
#!/usr/bin/awk -f
awk script here
and we call this as
$ ./script -Z
it will pass that option to Awk. But the script wanted to handle that option!
$ ./script -- -Z # process -Z as argument to the script
and wouldn't it be nice if we could hide this "--" argument in the hash bang?
With my proposal you could do that:
#!/usr/bin/env :awk:-f:{}:--
Now speaking of Awk, GNU awk has solved this particular problem itself. It has the option -E/--exec which works like -f, but is the last option to be processed.
(Any of these kinds of issues can be solved locally for a given interpreter, if you control its implementation.)