モチベーション
できるのか・・・?
結論として「できます。」
下ごしらえ
必要な物が何点かありますので、それを用意します。
sbtのドキュメント では conscript を使いなされと書いてますが、 裏で知らないものがインストールされるのもちょっと気持ちが悪いので、必要な物を手で準備します。
1. sbt-launch.jar
https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.9/sbt-launch.jar
こちらのURLからダウンロードします。
$ wget https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.9/sbt-launch.jar
ってかんじですね。
2. scalas というスクリプト
#!/bin/sh java -Dsbt.main.class=sbt.ScriptMain -Dsbt.boot.directory=$HOME/.sbt/boot -jar `dirname $0`/sbt-launch.jar "$@"
この2つを同一のディレクトリに入れ、パスを通しましょう
配置はこんな感じ
script-dir ├ sbt-launch.jar └ scalas
で、そこにPATHを通します。通します。(イカは参考、環境に合わせてPATHを通してね!)
echo "export PATH=$PATH:/{path}/{to}/script-dir/" >> ~/.bash_profile source ~/.bash_profile
コマンドはこんな感じで。
下ごしらえは完了!!
バイバイ! shell script!! ← チョイ煽り
hello.scala
#!/usr/bin/env scalas /*** scalaVersion := "2.11.7" */ println("Hello " + args.toList.headOption.getOrElse("World"))
で、ファイルができたら実行します。
./hello.scala
sbtがコンパイルするので若干もっさりと待たされた後に
Hello World
と表示されたらOKです。