Scripting In Kotlin Language



Kotlin can also be run as a script. If bash or perl is not for you, now you have an alternarive

lets write our first simple scipt in kotlin language.

for(k in 1..10){
    println("Kotlin is love");
}

save this file as kotlinLove.kts , important thing to notice here is .kts extention. The extention for kotlin script file should be .kts.

To run this script file, navigate to folder where you saved this file and "Open Command Window" in that folder by pressing Shift + Right Click on mouse. After opening Command Window type this command to run kotlin script

kotlinc kotlinLove.kts -script

and you will get this output

C:\Users\azeem\Desktop\Kotlin Lectures>kotlinc kotlinLove.kts -script
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love
Kotlin is love