Skip to content

Instantly share code, notes, and snippets.

@andirady
Last active September 17, 2021 23:43
Show Gist options
  • Select an option

  • Save andirady/be9088908459503f0363eaca4d670f74 to your computer and use it in GitHub Desktop.

Select an option

Save andirady/be9088908459503f0363eaca4d670f74 to your computer and use it in GitHub Desktop.
Run Java as a script. Requires Java > 9
///usr/bin/env java $0 $@; exit
public class hello {
public static void main(String[] args) {
System.out.println("I'm a script! Or am I? 😉");
}
}
/* to run it, execute a follows:
$ ./hello.java
*/
@andirady

Copy link
Copy Markdown
Author

Apparently, you don't have to make it executable. This may lead to security issues. 🤔

@andirady

Copy link
Copy Markdown
Author

Updated to simpler header. Inspired by jbang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment