Skip to content

Instantly share code, notes, and snippets.

@timhughes
Forked from phlash/Ick.java
Created September 10, 2018 15:24
Show Gist options
  • Select an option

  • Save timhughes/e7be7000694041af17f42800560f95a0 to your computer and use it in GitHub Desktop.

Select an option

Save timhughes/e7be7000694041af17f42800560f95a0 to your computer and use it in GitHub Desktop.

Revisions

  1. @phlash phlash created this gist Mar 2, 2018.
    31 changes: 31 additions & 0 deletions Ick.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/sh
    # This self-executing Java program uses the following /embedded shell script/ to compile & execute itself..

    # magic constant holding length of script
    SKIP=26

    # parse our name..
    FILE=`basename $0 .java`

    # get some working space, clean up old crud
    WORK=/tmp/java-hack
    mkdir -p $WORK
    find $WORK -mtime 7 |xargs rm -f

    # transform ourselves to compilable Java (aka, strip the shell script head), save the timestamp
    tail +$SKIP $0 > $WORK/$FILE.java
    touch -r $0 $WORK/$FILE.java

    # compile if required..
    [ -r $WORK/$FILE.class -a $WORK/$FILE.java -ot $WORK/$FILE.class ] || javac -d $WORK $WORK/$FILE.java

    # execute..
    java -cp $WORK $FILE $*
    exit $?
    ---------- Write some Java dude! ----------

    public class Ick {
    public static void main(String[] args) {
    System.out.println("Whoo Hooo!");
    }
    }