Subject: bug#21672: closed (Re: bug#21672: env is not splitting command and argument as suggested by the synopsis)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 12 Oct 2015 15:41:03 +0000

Your bug report

#21672: env is not splitting command and argument as suggested by the synopsis

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
21672: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21672
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#21672: env is not splitting command and argument as suggested by the synopsis
From: Eric Blake <[email-masked]>
To: Esli <[email-masked]>, [email-masked]
Date: Mon, 12 Oct 2015 09:40:37 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 21672 notabug
thanks

On 10/12/2015 02:48 AM, Esli wrote:
> Hello,
> 
>  
> 
>   env is not splitting command and argument as suggested by the synopsis:

Thanks for the report.  However, this is a misunderstanding on your part
on how the kernel implements #! on your system, and has nothing to do
with env.  The same would happen for any other attempt you make on your
system to write a shebang line with more than one set of space separations.

In short, shebangs differ tremendously across systems in how they
behave, and so the common subset that you can portably rely on is
severely limited in what it can do.

> #!/usr/bin/env perl -w
> 
> produces:
> 
> /usr/bin/env: perl -w: No such file or directory

That's because on your system, #! magic supports exactly ONE argument,
whitespace included, and does NOT break it into words in the same way
the shell does.  So your kernel is invoking '/usr/bin/env' 'perl -w',
and env is blindly trying to execute 'perl -w' (which does not exist),
exactly as requested.  But it is not env's job to do word splitting.

You cannot mix /usr/bin/env PROG and options to PROG in the same #!
shebang.  It is not portable.  But it is a limitation of your system,
and not something env can work around.

If you were to use '#!/path/to/perl -w', then your kernel would attempt
to invoke '/path/to/perl' '-w'.  The trick for this is then determining
at installation time what to place in the file for /path/to/perl, since
there is no canonical location for perl across all systems.

Also, the perl documentation includes some hints on how to use
/usr/bin/env perl as the shebang line, and then, separate from that
line, enable options that you can't portably include in the shebang.
But as this is not the perl mailing list, and I'm not the expert in it,
I'm not going to go trying to find that documentation right now.

Therefore, I'm closing this as not a coreutils bug, although you should
feel free to add further comments on the topic as desired.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Subject: env is not splitting command and argument as suggested by the synopsis
From: Esli <[email-masked]>
To: <[email-masked]>
Date: Mon, 12 Oct 2015 10:48:55 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

  env is not splitting command and argument as suggested by the synopsis:

SYNOPSIS

       env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

Example:

#!/usr/bin/env perl -w

produces:

/usr/bin/env: perl -w: No such file or directory

Apparently, env is looking for command "perl -w", not for command "perl" and
than passing him "-w"

Regards

   Petr