Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Speaking of funny shebangs, I came up with this to shell execute prolog .pl files, but it should work for any scripting language that has /**/-comments but doesn't support #-comments or #! shebangs specifically:

    /*usr/bin/env scryer-prolog "$0" "$@" ; exit #*/
From my original comment https://github.com/mthom/scryer-prolog/issues/2170#issuecomm... :

> The way this works is that this test.pl is both a valid shell file and prolog file. When executing as shell the first line finds and executes /usr/bin/env after searching for the glob pattern /*usr/bin/env. env then executes scryer-prolog "test.pl" which runs the prolog file as a module and halts; of course prolog ignores the first line as a comment /* ... */. Then the shell continues and executes the next command after ; which is exit which stops execution so the rest of the file (which is not valid shell) is ignored. The # makes the shell evaluator ignore prolog comment closer */ to prevent it from printing an error.

This may be the best and worst thing I have ever created.



Similarly, make go source executable : https://unix.stackexchange.com/questions/162531/shebang-star...

also, my contribution, make C programs executable:

    $ cat cute-use-of-slash-slash.c
    //usr/bin/env sh -c 'p=$(expr '"_$0"' : "_\(.*\)\.[^.]*"); make $p > /dev/null && $p'; exit

    #include <stdio.h>

    int main()
    {
        puts("hello world");
    }
    $ chmod  +x cute-use-of-slash-slash.c
    $ ./cute-use-of-slash-slash.c
    hello world
    $ $(pwd)/cute-use-of-slash-slash.c
    hello world
    $ ../cc/cute-use-of-slash-slash.c
    hello world
    $ sed -i -e s/hello/bye/ cute-use-of-slash-slash.c
    $ ./cute-use-of-slash-slash.c
    bye world
    $


I didn't think of this but I use it:

  % ./hworld.tcl  
  Hello, world.
  % cat hworld.tcl 
  #!/bin/sh
  # the next line restarts using tcl \
  exec tclsh "$0" "$@"
  puts "Hello, world."
  % 
Turns-out that in TCL you can line continue a comment :)


Oh my god this is amazing. We need to fix some of the IO redirect in Scryer and then this will be a perfect replacement for bash scripts <3

You rock!




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: