Re:Shebang Quine
by knodi123 on Friday May 20, 2016 @11:05AM
(#11738396)
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.
Re:Shebang Quine
by saganus on Friday May 20, 2016 @12:12PM
(#11739019)
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.
Re:Shebang Quine
by stouset on Friday May 20, 2016 @12:16PM
(#11739057)
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].
Re:Shebang Quine
by maze-le on Friday May 20, 2016 @11:54AM
(#11738846)
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.
Re:Shebang Quine
by hkjgkjy on Friday May 20, 2016 @12:43PM
(#11739321)
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?
Re:Shebang Quine
by maze-le on Friday May 20, 2016 @12:59PM
(#11739460)
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.
Re:Shebang Quine
by cyphar on Friday May 20, 2016 @12:22PM
(#11739120)
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).
Re:Shebang Quine
by hk__2 on Friday May 20, 2016 @04:05PM
(#11741039)
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.
Re:Shebang Quine
by cyphar on Friday May 20, 2016 @12:17PM
(#11739066)
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).
Re:Shebang Quine
by cyphar on Friday May 20, 2016 @09:14PM
(#11742681)
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.
Re:Shebang Quine
by cyphar on Friday May 20, 2016 @12:19PM
(#11739085)
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".
Re:Shebang Quine
by kovek on Friday May 20, 2016 @10:52AM
(#11738248)
More precisely:
- 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.
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.
In any other language, a program that opens and prints file containing its own source code is not considered a quine.
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.
For those who are puzzled by the term "quine": http://meta.codegolf.stackexchange.com/questions/4877/what-c...
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.
#!/bin/cat
[EDIT] as pointed out, I misspoke, and this is false.