The scala command executes the bytecode that is generated by the interpreter:
$ scala HelloWorld
Scala allows us to specify command options, such as the -classpath (alias -cp) option:
$ scala -cp classes HelloWorld
Before using the scala command to execute your source file(s), you should have a main method that acts as an entry point for your application. Otherwise, you should have an Object that extends Trait Scala.App, then all the code inside this object will be executed by the command. The following is the same Hello, world! example, but using the App trait:
#!/usr/bin/env Scala
object HelloWorld extends App {
println("Hello, world!")
}
HelloWorld.main(args)
The preceding script can be run directly from the command shell:
./script.sh
Note: we assume here that the file script.sh has the execute permission:
$ sudo chmod +x script.sh
Then, the search path for the scala command is specified in the $PATH environment variable.