Shorter Scala Script header

前端 未结 2 900
萌比男神i
萌比男神i 2021-02-08 20:05

It\'s possible to write shell scripts in Scala by starting a text file with:

#!/bin/sh
exec scala \"$0\" \"$@\"
!#

To ease script creation, I w

2条回答
  •  既然无缘
    2021-02-08 20:21

    In Scala 2.11, you can do it as follows (exactly as with most other languages):

    #!/usr/bin/env scala
    println(args.mkString(" "))
    

    In Scala 2.9.0.1, you can simply create the following script:

    test.scala

    #!/usr/bin/scala
    !#
    println(args.mkString(" "))
    

    and make it executable. (change the first line to path to your executable)

    Usage:

    # ./test.scala Hello world!
    Hello world!
    

提交回复
热议问题