Bug 199378 - #! does not seem to pass along arguments as expected
Bug#: 199378 Product:  Gentoo Linux Version: unspecified Platform: All
OS/Version: Linux Status: CLOSED Severity: normal Priority: P2
Resolution: INVALID Assigned To: kernel@gentoo.org Reported By: cyril.mougel@gmail.com
Component: Core system
URL: 
Summary: #! does not seem to pass along arguments as expected
Keywords:  
Status Whiteboard: 
Opened: 2007-11-16 17:15 0000
Description:   Opened: 2007-11-16 17:15 0000
When a want use hoe with the sow command. I have an error :

hello-18:08:30:~/$ sow whotowho
/usr/bin/env: ruby -ws: Aucun fichier ou répertoire de ce type

The error message in english is : No File or directory of this type


If I patch the file /usr/bin/sow and I delete the -ws in first line, I have no
error after.

Reproducible: Always

Steps to Reproduce:
1. sow project
2.
3.

------- Comment #1 From Jakub Moc (RETIRED) 2007-11-16 17:52:07 0000 -------
Which ebuild version is this about? Also, can you attach the patch?

------- Comment #2 From cyril mougel 2007-11-16 18:40:01 0000 -------
Sorry for my forget.

The version where I see this issue is the version 1.2.2.

I had made a patch and I attach it.

------- Comment #3 From cyril mougel 2007-11-16 18:40:36 0000 -------
Created an attachment (id=136101) [details]
patch for sow bin works

------- Comment #4 From Hans de Graaff 2007-11-17 10:03:13 0000 -------
As far as I can tell from the documentation this is a bug in /usr/bin/env
(which would be a bit weird). Could you provide emerge --info and the version
of coreutils on your system?

------- Comment #5 From Hans de Graaff 2007-11-17 10:50:54 0000 -------
According to the documentation, /usr/bin/env should handle the case where a
command and args are given. This works fine in a shell, e.g. "env ls -l" works
as expected, executing 'ls' with '-l' as the argument.

However, when this is done in a shebang file like this:

#!/usr/bin/env ls -l

then env tries to execute 'ls -l' as a command, which obviously fails. I don't
think that env itself is to blame here, but just gets the rest of the line as a
single argument instead of multiple arguments. 

------- Comment #6 From Hans de Graaff 2007-11-17 10:51:43 0000 -------
Created an attachment (id=136133) [details]
emerge --info output

My emerge --info output.

------- Comment #7 From SpanKY 2007-11-18 02:29:08 0000 -------
has nothing to do with /usr/bin/env

the kernel parses #! and passes those to userspace

------- Comment #8 From Duane Griffin 2007-11-18 12:07:03 0000 -------
This is not a bug. It is the intended, albeit surprising, behaviour. On linux
shebang invocations of an interpreter will be passed a maximum of one argument.
Space separated words will be passed as one string. It is one of those lovable
little *nix quirks that trips everyone up the first time they come across it.

From "man execve":

"The  semantics of the optional-arg argument of an interpreter script vary
across implementations. On Linux, the entire string following the interpreter
name is passed as a single argument to the interpreter, and this string can
include white space. However, behavior differs on some other systems. Some
systems use the first white space to terminate optional-arg. On some systems,
an interpreter script can have multiple arguments, and white spaces in
optional-arg are used to delimit the arguments."

There is a rather good and comprehensive discussion of the exact semantics of
shebang invocations here:

http://homepages.cwi.nl/~aeb/std/hashexclam-1.html

------- Comment #9 From Hans de Graaff 2007-11-18 13:42:20 0000 -------
Re-opening because the problem from the original bug reporter it not solved.

There are actually a number of bugs for this upstream:
http://rubyforge.org/search/?type_of_search=artifact&group_id=1513&atid=5921&words=sow&Search=Search


In fact, one of these bugs refers to a fix for this in rubygems. rubygems
should rewrite "/usr/bin/env ruby" interpreters on installation to use the
local path, ie. /usr/bin/ruby, but this was broken.

dev-ruby/rubygems-0.9.4-r2 should fix this. To confirm, emerge this version of
rubygems first, and then re-emerge hoe.

------- Comment #10 From Jakub Moc (RETIRED) 2007-12-17 07:05:08 0000 -------
*** Bug 202546 has been marked as a duplicate of this bug. ***

------- Comment #11 From Hans de Graaff 2007-12-17 19:11:17 0000 -------
I've asked for rubygems-0.9.4-r2 to be stabilized in bug 202608 so that the fix
will become more widely available.