2015-07-10 33 views
1

我該如何編寫下面的bash腳本來代替scala部分的實際代碼(在!#之後),以便從.scala文件中調用,然後調用它的主要方法?如何在scala exec bash文件中使用特定的文件名?

#!/bin/sh 
exec scala "$0" "[email protected]" 
!# 
object HelloWorld { 
    def main(args: Array[String]) { 
    println("Hello, world! " + args.toList) 
    } 
} 
HelloWorld.main(args) 

記住我沒有進入scalac

+0

也許這就是你實際上想要做的事情:http://stackoverflow.com/questions/15077341/whats-a-shebang-line-for-scala-that-doesnt-corrupt-mimetype – Kenster

+0

@Kenster不完全的!但這對未來有幫助 – Zee

回答

1

我相信你的意思是將文件分成兩個部分......

file.scala

object HelloWorld { 
    def main(args: Array[String]) { 
    println("Hello, world! " + args.toList) 
    } 
} 
HelloWorld.main(args) 

launch.sh

#!/bin/sh 
exec scala "file.scala" "[email protected]" 
+0

是的!這正是我所期待的! 出於好奇,「$ @」代表什麼? – Zee

+1

@Zee:[Source](http://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html)'$ @'是bash內部/特殊變量,擴展到所有收到的參數(在這個特殊情況下,由'launch.sh')。這意味着如果你調用'./launch.sh arg1 arg2',那麼''$ @「'將被擴展爲'arg1 arg2' –

相關問題