coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: env: add -S option (split string for shebang lines in scripts)


From: Pádraig Brady
Subject: Re: env: add -S option (split string for shebang lines in scripts)
Date: Wed, 25 Apr 2018 23:04:29 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 25/04/18 20:19, Kaz Kylheku (Coreutils) wrote:
> On 2018-04-24 22:09, Pádraig Brady wrote:
>> I was thinking that the explanation of -S in usage() would say 
>> something like:
>>
>>   -S, --split-string=S  process and split S into separate arguments
>>                           used to pass multiple arguments on shebang 
>> lines
> 
> One little problem with this FreeBSD design is that in spite of
> supporting variable substitution, it lacks the flexibility of
> specifying where among those arguments the script name is inserted!
> 
> Say we have a "#!/usr/bin/env -S lang ..." script called "foo.lang".
> 
> Suppose we want it so that "lang -f foo.lang -x" is invoked, where
> -f is the option to the lang interpreter telling it to read the
> script file foo.lang, and -x is an option to the foo.lang script
> itself.
> 
> It would be useful if the -S mechanism could indicate this insertion
> of foo.lang into the middle of the arguments.
> 
> The variable expansion mechanism could do it. Suppose that a certain
> reserved variable name like ${ENV_COMMAND} (not my actual suggestion)
> expands to the name of the last argument received by env.
> 
> Furthermore, when env is asked to expands this variable one or more
> times, it makes a note of this and then sets a flag which suppresses
> the script name from appearing in its usual position at the end.
> 
> Then this is possible:
> 
>      #!/usr/bin/env -S lang -f ${ENV_COMMAND} -x

This is a very good point. Thanks for bringing it up.
If we're taking the time to do this, we should make it generally usable.
This would be useful with for example:

  #!/usr/bin/env -S awk -f

Now that does work if awk would ignore any options after -f ...,
but it only ignores options it doesn't recognise :/,
so if you wanted to pass -f to the awk script for example you'd need this 
support.
Note one could hack it using ${_} which is generally set to the last arg, i.e.

  #!/usr/bin/env -S awk -F: -f ${_} --
  But then the awk script would need to ignore the first argument which is 
messy,
  and also ${_} may not be set in all contexts.

I suppose we could support the bash/ksh syntax of ${@:-1}
and once that variable is referenced it's not passed on.

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]