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: Bernhard Voelker
Subject: Re: env: add -S option (split string for shebang lines in scripts)
Date: Tue, 1 May 2018 17:47:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 04/28/2018 12:58 AM, Assaf Gordon wrote:
> Hello Eric, Bernhard,
> 
> Thank you for commenting, you raise many good point.
> Below are some ideas regarding them (combining replies to the last 4 emails).
> 
> On Fri, Apr 27, 2018 at 12:31 AM, Bernhard Voelker <address@hidden> wrote:
>> One nit: env -v shows a confusing error diagnostic when it is
>> separated from the -S option on the shebang line:
>>
>>   $ cat xxx
>>   #!src/env -v -S cat -n
>>   hello
>>
>>   $ ./xxx
>>   src/env: invalid option -- ' '
>>   Try 'src/env --help' for more information.
> 
> Agree, very confusing and unhelpful message.
> 
> For comparison, FreeBSD behaves the same:
> 
>   $ cat xxx
>   #!/usr/bin/env -v -S cat -n
>   hello
>   $ ./xxx
>   env: illegal option --
>   usage: env [-iv] [-P utilpath] [-S string] [-u name]
>              [name=value ...] [utility [argument ...]]
> 
> 
> But of course we can and should do better.
> 
> 
> On Fri, Apr 27, 2018 at 7:13 AM, Eric Blake <address@hidden> wrote:
>> We could include ' ' (and maybe '\t') as part of the short-option
>> optstring accepted in getopt_long(), as an undocumented silent no-op.
> 
> On Fri, Apr 27, 2018 at 8:22 AM, Eric Blake <address@hidden> wrote:
>> I tested it, and it DOES seem to work:
> [...]
>>        switch (optc)
>>          {
>> +        case ' ':
>> +        case '\t':
>> +        case '-':
>> +          /* Undocumented no-ops, to allow '-v -S' to behave like '-vS' */
>> +          break;
> 
> Good solution, thanks for testing it.
> 
> 
> I wonder - would it be better to detect this issue
> and report an informative error message instead of silently accepting it?
> 
> If GNU env accepts it, we create yet another (very subtle) difference
> between FreeBSD and GNU.
> If we reject it and explain why, we create a better user experience,
> but also promote portable scripting...

Good point.
After some playing with it, I also think it's better to err with a nice
diagnostic.  But even that isn't that easy.  Although ignoring ' ', '\t',
and '-' is a nice solution, it seems to get more ugly to handle other
cases.

> On Fri, Apr 27, 2018 at 12:57 PM, Eric Blake <address@hidden> wrote:
>> This is missing support for -P, which is one of the essential features
>> of FreeBSD env, per their man page:
> 
> I can certainly add support "-P" (I'll do it in a separate patch though).
> 
> Is "-P" (alternate path) something that is often requested?
> I do see a lot of questions about passing multiple arguments with 
> "#!/usr/bin/env",
> but I haven't noticed people asking about setting per-script non-standard 
> $PATH
> (but without changing the actual $PATH).

Isn't this the regular case with specifying the PATH variable?

  env PATH=/some:/path prg

Have a nice day,
Berny



reply via email to

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