1.环境 centos
scala2.10.2
2.简单的示例
# vi hello.sh
#!/bin/sh
exec scala "$0" "$@"
!#
println("HellO,Linux World")
这里的#! 表示解释执行此脚本的shell路径
$0表示绑定的脚本名称hello.sh
$@表示绑定的脚本输入参数
!#表示脚本头部声明结束
# chmod 755 hello.sh // chmod +x hello.sh
# ./hello.sh
HellO,Linux World
3.调用对象
# vi person.sh
#!/bin/sh
exec scala "$0" "$@"
!#
class Person(val firstName:String,val secondName:String){
override def toString()="firstName : " + firstName + ",secondName : " + secondName
}
println(new Person("Martin","Odersky"))
# chmod +x person.sh
# ./person.sh
firstName : Martin,secondName : Odersky
4.传递参数
# vi words.sh
#!/bin/sh
exec scala "$0" "$@"
!#
object Words {
def main(args : Array[String]): Unit={
println("start word main ...")
args.foreach(println(_))
}
}
# chmod 755 words.sh
# ./words.sh hello scala
start word main ...
hello
scala
5.复杂的脚本编写,如从mysql数据库读取数据