Note: We assume here the file script.sh has execute access and the search path for the scala command is specified in the PATH environment variable.

Compile it !

The scalac command compiles one (or more) Scala source file(s) and generates Java bytecode which can be executed on any standard JVM[3]; the Scala compiler works similarly to javac[4], the Java compiler of the Java SDK[5].

> scalac HelloWorld.scala

By default scalac generates the class files into the current working directory. You may specify a different output directory using the -d option.

> scalac -d classes HelloWorld.scala

Execute it !

The scala command executes the generated bytecode with the appropriate options:

> scala HelloWorld

scala allows us to specify command options, such as the -classpath (or -cp) option:

> scala -classpath classes HelloWorld

The argument of the scala command has to be a top-level object. If that object is followed by the clause extends Application, then all statements contained in that object will be executed; otherwise you have to add a method main which will act as the entry point of your program.