Basic scripting support for Kotlin


I've developed a little script (see attachment) to turn Kotlin into a scripting language. e.g.

EDIT: This script has now moved to removing the previous limitations. It’s been tested under OS X and Linux (and cygwin with a patched kolinc).

#!/usr/bin/env kotlin
println(“Hello from Kotlin!”)
for (arg in args) {
  println(“arg: $arg”)


  • Supports scripts where the first line is #! and wraps them in a main method
  • Supports standalone scripts with a main function
  • Caches compiled versions of scripts. (“Hello, world” seems to take around 3s to run with compilation and 200ms thereafter)


  • Currently OS X only (although it could easily be ported to any unix/cygwin)
  • Doesn’t support things like kotlinc being a symlink, honouring JAVA_HOME etc

Anyway, I thought others might find it useful while waiting for official scripting support (


Message was edited by: Andrew O’Malley



This is totally awesome! I think it would make a lot of sense to make it a full-featured project, i.e. fix the limitations you mention.

Do you mind to put it up on github so that we will be able to call for Kontributions to the project?




You’re welcome to use it however you like.

I guess the ultimate location for something like this would be along-side kotlinc in the distribution.
Or would you prefer me to put it in my own github repo until it matures?



Very interesting work! I installed msys on Windows, downloaded a md5 tool ( and changed the line

  md5=md5 -q "$1"


  md5=md5 -n "$1"

and it worked fine on Windows in msys console :slight_smile:


It would be great if you put it in your own repo for now. I'll be happy to help you find collaborators and finally add the tool to the Kotlin family.


Hi Andrey,

I’ve rewritten the script to remove the previous limitations and make it cross-platform (including removing the dependency on md5). I’ve tested it on OS X, Linux and cygwin.

It’s available here:



This may be a dumb question, but the docs for kotlin-script says it needs kotlinc in the path.  

I have no idea where to get kotlinc as an executable (I know there’s an ant task…), google hasn’t been any help either.


kotlinc zip contains executable scripts in "bin" directory


What is the kotlinc zip.. do you mean the kotlin zip on github?  There is only a "kotlin" in the bin directory, not kotlinc


You can get the Kotlin builds from Jetbrains' Team City site:

Under the “Compiler and Plugin” section there’s an “Artifacts” dropdown menu. You can download the kotlin zip file from there (it’s probably best sticking to a version that has been verifed). Within that .zip file there’s the kotlinc scripts (in the bin directory).