LinuxCommandLibrary

kotlin

runs Kotlin scripts and provides a REPL

TLDR

Run Kotlin script
$ kotlin [script.kts]
copy
Run with arguments
$ kotlin [script.kts] [arg1] [arg2]
copy
REPL mode
$ kotlin
copy
Execute expression
$ kotlin -e "println(\"Hello\")"
copy
Include classpath
$ kotlin -cp [lib.jar] [script.kts]
copy

SYNOPSIS

kotlin [options] script [args...]

DESCRIPTION

kotlin is the Kotlin runtime command that executes Kotlin scripts (.kts files) directly on the JVM without requiring a separate compilation step. It also provides an interactive Read-Eval-Print Loop (REPL) when invoked with no arguments, allowing you to experiment with Kotlin expressions and statements interactively.
The tool can evaluate single expressions from the command line using the `-e` flag, run script files with command-line arguments, and include additional JARs on the classpath for access to external libraries. Since Kotlin scripts run on the JVM, they have full access to the Java standard library and any Java or Kotlin libraries added to the classpath, making it suitable for automation tasks, quick prototyping, and build scripting.

PARAMETERS

SCRIPT

Kotlin script file (.kts).
-e EXPR
Evaluate expression.
-cp PATH
Classpath.
-J ARG
Pass argument to JVM.
--help
Display help information.

CAVEATS

Requires JVM. Scripts use .kts extension. Slower startup than compiled code.

HISTORY

Kotlin was created by JetBrains in 2011. The kotlin command runs scripts and provides the REPL.

SEE ALSO

kotlinc(1), java(1), gradle(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard