env bug ?

John Sellens jsellens-Iv5KO+h6AVB+Y12zHexnB0EOCMrvLtNR at public.gmane.org
Tue Mar 8 00:07:02 UTC 2005


| I seem to have a problem with env: a file that starts with:
| 
|     #!/usr/bin/env echo foo
|
| and is set +x and executes, will print:
|
|     /usr/bin/env: echo foo: No such file or directory

Hmmm - there seems to be something different in the way Linux does #!
lines than one might expect.  On my systems
    #!/usr/bin/env echo foo
in an executable file called /tmp/blah, when run via "/tmp/blah",
is equivalent to this typed at the shell

Linux:       /usr/bin/env "echo foo" /tmp/blah
FreeBSD:     /usr/bin/env echo foo /tmp/blah
Solaris 5.7  /usr/bin/env echo /tmp/blah


I'll claim that Linux is doing the unexpected, I think Solaris is
doing to "historical" behaviour, and FreeBSD is what one would
normally expect.

env is behaving correctly, based on the arguments it is given.
Some (including me) might claim that the kernel is invoking env
incorrectly.


| I tried it and got the same result, but when I put perl instead of echo 
| foo.  It worked.  I am assuming that the command not found is echo (an 
| internal shell command) and therefore not in the path.

Hmmm, for me
    #!/usr/bin/perl echo foo
results in
    Can't open perl script "echo foo": No such file or directory
which is consistent with the observed behaviour with "env".


Ths echo command is typically in the PATH (unless your PATH
inexplicably excludes /bin.  The command not found in the original
question was "echo foo" i.e. there was no executable file called
"echo foo" in the PATH (not surprisingly).


John
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list