David Portabella David Portabella - 6 months ago 43
Bash Question

run a Ammonite scala script without typing amm

I try to use Ammonite to write scripts written in Scala
http://www.lihaoyi.com/Ammonite/#Scripting

Example from the website: Args.scala

val x = 1
import ammonite.ops._
def main(i: Int, s: String, path: Path = cwd) = {
println(s"Hello! ${s * i} ${path.relativeTo(cwd)}.")
}


to run it:

$ amm Args.scala 3 Moo


is it possible to write a script that can run by itself, instead of calling
amm Args.scala
, such as?

$ Args.scala 3 Moo


i tried adding the following to the head of Args.scala:

#!/usr/local/bin/amm


and making it executable with
chmod +x Args.scala
, but it does not work. it is as if bash (instead of amm) is running the script, and don't understand the first command
val x = 1
.

Answer

Try with this header #!/usr/bin/env amm.

Comments