Kotlin をコンソールで使う方法を紹介します。 LLではよくあるインタープリタが Kotlin でも使えるようになります。
ここで紹介する方法は、 OS X 含む Unix ベース のシステムで活用可能です。
手順
- SDKMAN! をインストールします。
- コマンド
-
|
curl -s https://get.sdkman.io | bash |
- アウトプット
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Looking for a previous installation of SDKMAN... Looking for unzip... Looking for zip... Looking for curl... Looking for sed... Installing SDKMAN scripts... Create distribution directories... Getting available candidates... Prime the config file... Download script archive... ######################################################################## 100.0% Extract script archive... Install scripts... Set version to 5.5.13+272 ... Attempt update of interactive bash profile... Added sdkman init snippet to /home/user/.bashrc Attempt update of zsh profile... Updated existing /home/user/.zshrc All done! Please open a new terminal, or run the following in the existing one: source "/home/user/.sdkman/bin/sdkman-init.sh" Then issue the following command: sdk help |
- Kotlinコンパイラ・インタープリタをインストールします。
- コマンド
-
- アウトプット
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
==== BROADCAST ================================================================= * 04/12/17: Gradle 4.4-rc-6 released on SDKMAN! #gradle * 30/11/17: Gradle 4.4-rc-5 released on SDKMAN! #gradle * 29/11/17: Groovy 3.0.0-alpha-1 released on SDKMAN! #groovylang ================================================================================ Downloading: kotlin 1.2.0 In progress... ######################################################################## 100.0%j Installing: kotlin 1.2.0 Done installing! Setting kotlin 1.2.0 as default. |
- Kotlinを使えるようにします。 シェルを再起動する場合はやらなくてもいいです。
- コマンド
-
|
source "/home/user/.sdkman/bin/sdkman-init.sh" |
Kotlin インタープリタ
Kotlin インタープリタ は コマンド kotlinc
を実行すると起動します。
実行例
|
Welcome to Kotlin version 1.2.0 (JRE 1.8.0_151-8u151-b12-0ubuntu0.17.04.2-b12) Type :help for help, :quit for quit >>> 4 + 1 5 >>> println("hello") hello >>> |
終了するときは、 :quit
を入力するか、 Ctrl + D を押します。
kotlinc file_path.kts [args...]
のようにすると、 Kotlin で書かれたスクリプトを実行することもできます。
A Life Summary of an Gypsy