- The shell finds opens up the file you want to execute
- It gets the first line of the file
- It figures out what program to execute
- It calls fork()
- In the new process, it executes the program (using exec()) and passes the file as the input to the program.
I remember being surprised by this and then realising, "wait, of course it's in the kernel -- that's so much nicer from a usability and sanity standpoint".
It’s often used to have your shell scripts fail fast by using `#! /usr/bin/bash -e`; which you could also do by using `set -e` at the beginning of the script but that’s less elegant.
I'm fairly sure `#!./quine` will cause an error because there's a limit of 5 recursive checks to find the interpreter of a script (fs/binfmt_script.c).
Presumably then, whatever shell you're using decides to just execute the code as a subshell rather than use execve(2). Can you dtrace it to figure out whether it actually calls execve(2)?
0 51617 execve:entry sh ./quine
1 51617 execve:entry sh /bin/sh
1 51617 execve:entry sh /bin/cat
Altho this is the first time I use dtrace. I can try to run another command you can ask me to.
My login shell is the Bourne shell. However I tried bash, csh and tcsh too, it works, so it's probably the system level code that substitutes /bin/sh (maybe because it's my login shell?) to the interpreter.
wow, that's incredible. there's, like, 4 different techniques going on in there that I don't understand- and I would have said I understood javascript pretty well.
This is extremely cool, however the source code does look a little different than the output (the output only has '#' chars, but the source has letters and other chars besides #). Does that still count as a quine? (don't really care though... this is very cool).
Any idea how this works? It's just to much for my mind to bear I think.
I'm not sure what you're talking about. The output is the entire source with the central globe rotated by a user-selectable number of degrees, including 0. The output isn't just the globe in the center.
Edit: Ah, nvm. It looks like this is a Javascript port of a famous Ruby quine from 2010, the Qlobe[1].
I is not 'exactly' a quine, because the tool 'cat' is a program on its own, and not a shell command. Still, it is an entertaining and unexpected outcome.
I'm curious to know where the line of a "program" goes. I imagine a OS without file system, but only with functions (like as if emacs was an OS). Would a function then be called a program?
Well, if your EmacsOS allocates exclusive adress-space for the function-call, so that it can be executed in a very own execution context, independent of other function-calls... then you could call it a program.
I like the fact that #!/proc/self/exe causes the interpreter to be the calling program (since the interpreter is evaluated in the context of the calling program, from the kernel).
55 comments
[ 1.9 ms ] story [ 105 ms ] thread#!/bin/cat
[EDIT] as pointed out, I misspoke, and this is false.
Any other funny commands? ls -l is cool too.
I'm not sure I've used it since, but I still like the xgraph thing.
Refer to sys/kern/imgact_shell.c and ^do_execve in sys/kern/kern_exec.c, I skimmed but could not find why it ran.
My login shell is the Bourne shell. However I tried bash, csh and tcsh too, it works, so it's probably the system level code that substitutes /bin/sh (maybe because it's my login shell?) to the interpreter.
For those who are puzzled by the term "quine": http://meta.codegolf.stackexchange.com/questions/4877/what-c...
http://aem1k.com/world/
https://github.com/mame/quine-relay
https://github.com/mame/quine-relay/blob/master/thumbnail.pn...
(Attention to detail, they haz it.)
Any idea how this works? It's just to much for my mind to bear I think.
Edit: Ah, nvm. It looks like this is a Javascript port of a famous Ruby quine from 2010, the Qlobe[1].
[1]: http://d.hatena.ne.jp/ku-ma-me/20100905/p1
https://jsfiddle.net/f17yr7qh/
For example, line 9 of the source:
~(32sin(o)/* , (W#####Xx######.P^ T % */sin(.5+y/7))\
You can see that there are more chars than just '#' inside the "globe", like '(W' and 'Xx' and '.P^'
I even changed those inside the globe and the effect is non obvious. Sometimes it stops working sometimes it works fine with other chars. No idea why.
But in what language is this "program" written?
The best I can guess is that the unix shebang hack/convention is a (very, very minimal) language all of its own.
In any other language, a program that opens and prints file containing its own source code is not considered a quine.