Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Matthias Urlichs
Hi,

Thorsten Glaser:
> tglase@tglase:~ $ cat x
> #?/usr/bin/python
> import sys
> print sys.version
> tglase@tglase:~ $ ls -l x
> -rwxr-xr-x 1 tglase tglase 47 Apr  4 12:54 x
> tglase@tglase:~ $ ./x
> import.im6: unable to grab mouse ': Resource temporarily unavailable @ 
> error/xwindow.c/XSelectWindow/9047.
> sys.version
> tglase@tglase:~ $ b/mksh
> tglase@tglase:~ $ ./x
> 2.7.6 (default, Mar 22 2014, 17:40:27) 
> [GCC 4.8.2]
> 
This just says that mksh handles #! scripts like no other shell.
Doesn't mean that it's a good (or bad) idea.

In fact, I wonder whether anything would break if we removed the ability
to run shebang-less scripts from our shells.

Currently, they do this:

* bash opens the script and interprets it
* ash dash immediately execve() /bin/sh with the script
* mksh obviously opens the file and tries to read the #! line, which
  seems pointless because the kernel already did this.

This gets interesting if you point the #! line to something which is not an
executable.

* ash bash dash obviously behave as if the #! line was not there and
  interpret the script.
* mksh reports the ENOEXEC. I actually like that.

-- 
-- Matthias Urlichs


signature.asc
Description: Digital signature


Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Andrey Rahmatullin
On Fri, Apr 04, 2014 at 02:04:32PM +0200, Salvo Tomaselli wrote:
> > > Sure. I’ve patched mksh 
> > 
> > mksh doesn't count as a reference.
> Did you even read before replying? He patched it to use #? Instead of #! that 
> was using.
> He was sure about it being there because he had patched it to behave 
> differently.
And all of that was to prove mksh does something, which cannot be used as
an argument about general or standardized behavior, or something.

-- 
WBR, wRAR


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/20140404122721.ga29...@belkar.wrar.name



Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Salvo Tomaselli
In data venerdì 04 aprile 2014 17.38.12, Andrey Rahmatullin ha scritto:
> > Sure. I’ve patched mksh 
> 
> mksh doesn't count as a reference.
Did you even read before replying? He patched it to use #? Instead of #! that 
was using.
He was sure about it being there because he had patched it to behave 
differently.

-- 

Salvo Tomaselli

"Io non mi sento obbligato a credere che lo stesso Dio che ci ha dotato di
senso, ragione ed intelletto intendesse che noi ne facessimo a meno."
-- Galileo Galilei

http://ltworf.github.io/ltworf/


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/2629335.D8GMTTWuuY@vulcano



Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Jakub Wilk

* Thorsten Glaser , 2014-04-04, 12:58:

Try duckduckgoïng instead ☻ or searching POSIX, or something.


SUSv4 “helpfully” says:

If the first line of a file of shell commands starts with the characters 
"#!", the results are unspecified.


--
Jakub Wilk


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/20140404114816.ga3...@jwilk.net



Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Ansgar Burchardt
Hi,

Thorsten Glaser  writes:
> On Fri, 4 Apr 2014, Chow Loong Jin wrote:
>
>> Are you sure about this?
>
> Yes.
>
>> Some references would be helpful. I can't seem to find anything on this 
>> through
>
> Sure. I’ve patched mksh to use “#?” ipv “#!” as shebang, to
> simulate a kernel not supporting the shebang:
[...]
> Try duckduckgoïng instead ☻ or searching POSIX, or something.

I tried and found that POSIX says the shell shall try execve(), and if
that fails 'the shell shall execute a command equivalent to having a
shell invoked with the pathname resulting from the search as its first
operand, with any remaining arguments passed to the new shell, except
that the value of "$0" in the new shell may be set to the command
name.'[1] No #! involved.

  [1] 


Furthermore Wikipedia says "For this reason and because POSIX does not
standardize path names, POSIX does not standardize the feature."[2].

  [2] 

I'm interested where POSIX says what you are sure it says (that the
shell is responsible for evaluating #!).

> Also, “man mksh” look for EXECSHELL (which is the interpreter the
> shell uses if the script doesn’t even have a shebang).

I don't think the manual for a not commonly used shell is a good
reference...

Ansgar


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/87ha69xqyj@deep-thought.43-1.org



Re: shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Andrey Rahmatullin
On Fri, Apr 04, 2014 at 12:58:23PM +0200, Thorsten Glaser wrote:
> > Are you sure about this?
> 
> Yes.
> 
> > Some references would be helpful. I can't seem to find anything on this 
> > through
> 
> Sure. I’ve patched mksh 
mksh doesn't count as a reference.

> > some cursory googling.
> Try duckduckgoïng instead ☻ or searching POSIX, or something.
That's quite helpful.

-- 
WBR, wRAR


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/20140404113812.ga27...@belkar.wrar.name



shebang (was Re: systemd - some more considerations)

2014-04-04 Thread Thorsten Glaser
On Fri, 4 Apr 2014, Chow Loong Jin wrote:

> Are you sure about this?

Yes.

> Some references would be helpful. I can't seem to find anything on this 
> through

Sure. I’ve patched mksh to use “#?” ipv “#!” as shebang, to
simulate a kernel not supporting the shebang:

Index: exec.c
===
RCS file: /cvs/src/bin/mksh/exec.c,v
retrieving revision 1.129
diff -u -p -u -p -r1.129 exec.c
--- exec.c  11 Jan 2014 16:26:27 -  1.129
+++ exec.c  4 Apr 2014 09:34:58 -
@@ -893,7 +893,7 @@ scriptexec(struct op *tp, const char **a
/* restore begin of shebang position (buf+0 or buf+3) */
cp = (unsigned char *)(buf + fd);
/* bail out if read error (above) or no shebang */
-   if ((cp[0] != '#') || (cp[1] != '!'))
+   if ((cp[0] != '#') || (cp[1] != '?'))
goto noshebang;
 
cp += 2;

(Some comment on the side: “buf+0 or buf+3” is because mksh additionally
strips an UTF-8 BOM before the shebang. This is beyond standard.)

Then I run this:

tglase@tglase:~ $ cat x
#?/usr/bin/python
import sys
print sys.version
tglase@tglase:~ $ ls -l x
-rwxr-xr-x 1 tglase tglase 47 Apr  4 12:54 x
tglase@tglase:~ $ ./x
import.im6: unable to grab mouse ': Resource temporarily unavailable @ 
error/xwindow.c/XSelectWindow/9047.
sys.version
tglase@tglase:~ $ b/mksh
tglase@tglase:~ $ ./x
2.7.6 (default, Mar 22 2014, 17:40:27) 
[GCC 4.8.2]

(This is Debian sid/i386 (still waiting for x32, that’s why i386).)

> some cursory googling.

Try duckduckgoïng instead ☻ or searching POSIX, or something.

Also, “man mksh” look for EXECSHELL (which is the interpreter the
shell uses if the script doesn’t even have a shebang).

bye,
//mirabilos
-- 
Sometimes they [people] care too much: pretty printers [and syntax highligh-
ting, d.A.] mechanically produce pretty output that accentuates irrelevant
detail in the program, which is as sensible as putting all the prepositions
in English text in bold font.   -- Rob Pike in "Notes on Programming in C"


--
To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
https://lists.debian.org/alpine.deb.2.10.1404041254520.25...@tglase.lan.tarent.de