News for hackers. Stuff that matters.
Re:Shebang Quine by geon on Friday May 20, 2016 @10:39AM (#11738128)
I was thinking of unorthodox uses for the shebang, and realized cat gives you a very succinct quine.

Any other funny commands? ls -l is cool too.

Re:Shebang Quine by philh on Friday May 20, 2016 @10:53AM (#11738254)
Ages ago I wrote a simple command that let you do shell scripting in the shebang line. http://reasonableapproximation.net/2010/07/27/silly-things-t...

I'm not sure I've used it since, but I still like the xgraph thing.

Re:Shebang Quine by jmiserez on Friday May 20, 2016 @01:27PM (#11739720)
Very interesting and a good read. I was not aware that you could pass an argument in the shebang line.
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 kylek on Friday May 20, 2016 @03:54PM (#11740936)
This is pretty great little read, much appreciated
Re:Shebang Quine by gkya on Friday May 20, 2016 @11:37AM (#11738695)

  #!/bin/rm
  #!/sbin/md5
  #!/usr/bin/file
  #!/usr/bin/du -h
And yet another quine:

  #!./quine
  cat $0
Edit: I was not sure about #!/sbin/poweroff, and I cannot try now, so removed.
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 gkya on Friday May 20, 2016 @12:44PM (#11739323)
Ran it, works. I'm on freebsd 10.3 BTW.
Re:Shebang Quine by cyphar on Friday May 20, 2016 @01:22PM (#11739680)
On Linux you get ELOOP. How does that resolution even work on FreeBSD? Why does it resolve to $SHELL (the file resolves to itself).
Re:Shebang Quine by usmannk on Friday May 20, 2016 @01:51PM (#11739947)
Yeah, I don't see that working unless the shebang is changed to `#!/bin/sh`?
Re:Shebang Quine by gkya on Friday May 20, 2016 @02:10PM (#11740104)
execve(2) on my machine defines ELOOP lie this: Too many symbolic links were encountered in translating the pathname.

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.

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)?
Re:Shebang Quine by gkya on Friday May 20, 2016 @09:48PM (#11742784)
After running dtrace as

  $ sudo dtrace -n 'syscall::execve*:entry { printf("%s %s", execname, copyinstr(arg0)); }'
I had this output

    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 Saturday May 21, 2016 @11:28AM (#11744976)
I think shells are doing that. Otherwise you wouldn't see the execve("/bin/sh") syscall entry (it would get silently translated inside the kernel).
Re:Shebang Quine by djsumdog on Friday May 20, 2016 @02:07PM (#11740088)
Huh...yea, I never though about how the first argument to a program is always itself.
Re:Shebang Quine by Null-Set on Friday May 20, 2016 @12:51PM (#11739388)
rm, with self cleaning action!