Linux command
kotlin 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Run a Kotlin script
kotlin script.kts
Run a script with arguments
kotlin script.kts [arg1] [arg2]
Start the interactive REPL
kotlin
Evaluate an expression
kotlin -e "println(\"Hello\")"
Run a script with additional classpath JARs
kotlin -cp [lib.jar] script.kts
Pass JVM options
kotlin -J-Xmx512m script.kts
说明
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.
参数
- -e _EXPR_
- Evaluate expression.
- -cp _PATH_
- Classpath.
- -J _ARG_
- Pass argument to JVM (e.g., -J-Xmx512m).
- -nowarn
- Suppress warning messages.
- -version
- Display the Kotlin version.
- --help
- Display help information.
FAQ
What is the kotlin command used for?
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.
How do I run a basic kotlin example?
Run `kotlin script.kts` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e _EXPR_ do in kotlin?
Evaluate expression.