This repository provides examples on using Kotlin Shell library
The examples can be run both via command line and Intellij IDEA.
All examples from kotlin
can be executes as scripts and all examples from kts
can be executed as part of Kotlin code.
As scripting support in Intellij IDEA is still under development, examples may not run properly on every versions. Despite the highlighting and completion should work fine.
type:
./gradlew -Psample=[RELATIVE-CLASS-PATH] -Plogs=true execute [--args="ARGS"]
example:
$ cd kotlin
$ ./gradlew -Psample=basic.HelloKt execute
hello world!
To see logs add -Plogs=true
parameter.
To run scripts you need kshell installed
type:
cd kts
kshell src/kotlin/[PATH-TO-SAMPLE] [ARGS]
example:
$ cd kts
$ kshell src/kotlin/basic/hello.sh.kts
hello world!
After importing Gradle project you will be able to run main()
functions in sample classes.
After importing Gradle project you will be able to run script files.
File kts/fileTemplate_sh_kts
contains template definition for Intellij.
To use it put this file in ~/Library/Preferences/IntelliJIdea/fileTemplates
with name KotlinShell.sh.kts
.
Kotlin Shell features slf4j
logging interface.
All examples use NOP logger by default. Configurations for loggers can be found under resources/log4j2.xml
.
By default Gradle project imports NOP logger. To change it use these instructions.
Both kshell
and Gradle uses NOP logger by default. You can change this dependency manually to see the logs.
In sidebyside
package there are located side by side examples of scripts written with Kotlin Shell and Bash.
They are always equal in terms of evaluation.