scala(1)
π scala(1) β the manual page, bestie edition π
okay so you opened the scala manual page from the USER COMMANDS section and honestly? iconic. this is your girl's guide to running Scala 2 code and i'm gonna hold your hand through every single flag. no gatekeeping here. π«Ά
β¨ NAME β¨
scala β Run code in the Scala 2 language. that's it, that's the whole vibe.
β¨ SYNOPSIS β¨
scala [ <option> ]... [ <torun> <argument>... ]
πΈ PARAMETERS πΈ
<compiler-option>β literally anyscalacoption you want. go checkscalac(1)if you need the whole menu, she's got it all.-howtorun:<how>β tells scala how to execute<torun>, assuming<torun>even showed up. your choices for<how>areguess(the default, she's a mind reader),script,jar, andobject.-i <file>β asks for a file to be pre-loaded. only meaningful for interactive shells, so don't get cute with it elsewhere. π-e <string>β asks that its argument get executed as Scala code. yes, straight up. π-savecompiledβ saves this compiled version of scripts so later runs of the same script go zoom. when you run a script, the compiled version gets saved in a file with the same name as the script but with an extension of.jar. on subsequent runs of that same script, the pre-compiled.jarfile gets used if it's newer than the script file. so fresh, so fast. β¨-nocompdaemonβ do NOT use thefscoffline compiler. respectfully declining.-ncβ same as-nocompdaemon. the lazy girlie abbreviation, we love her.-Dproperty=valueβ set a Java system property. if no value is specified, then the property is set to the empty string. she said "fine, empty string then." π<torun>β a top-level object or a script file to run.<argument>β an arguments to pass to<torun>. (yes girl, that's what the page says and i'm not touching it. π)
π DESCRIPTION π
the scala utility runs Scala code using a Java runtime environment. the Scala code to run is specified in one of three ways, and here's the lineup:
- with no arguments specified, a Scala shell starts and reads commands interactively. the REPL has entered the chat.
- with
-howtorun:objectspecified, the fully qualified name of a top-level Scala object may be specified. the object should previously have been compiled usingscalac(1). no skipping steps bestie. - with
-howtorun:scriptspecified, a file containing Scala code may be specified.
if -howtorun: is left as the default (guess), then the scala command will check whether a file of the specified name exists. if it does, then it will treat it as a script file; if it does not, then it will treat it as the name of an object. she's guessing, but she's guessing correctly.
in all three cases, arbitrary scalac options may be specified. the most common option is to specify a classpath with -classpath, but see the scalac(1) page for full details.
if an object is specified to run, then that object must be a top-level Scala object with the specified name. the object must define a method main with the following signature:
def main(args: Array[String]): Unit
the method must return a Unit value, and it must accept a String array as a parameter. all arguments specified on the command line will be passed as arguments to the main method. signature check: passed. π
if a script file is specified to run, then the file is read and all Scala statements and declarations in the file are processed in order. any arguments specified will be available via the args variable.
script files may have an optional header that is ignored if present. there are two ways to format the header: either beginning with #! and ending with !#, or beginning with ::#! and ending with ::!#.
such a header must have each header boundary start at the beginning of a line. headers can be used to make stand-alone script files, as shown in the examples below. stand-alone script files are main character energy, no cap.
when running a script or using -e, an already running compilation daemon (fsc) is used, or a new one started on demand. the -nocompdaemon or -nc option can be used to prevent this.
if scala is run from an sbaz(1) directory, then it will add to its classpath any jars installed in the lib directory of the sbaz directory. additionally, if no -classpath option is specified, then scala will add ".", the current directory, to the end of the classpath.
β OPTIONS β
okay so if any compiler options are specified, they must be first in the command line and must be followed by a bare hypen ("-") character. (yes, "hypen". i said what i said, i'm being faithful. π)
if no arguments are specified after the optional compiler arguments, then an interactive Scala shell is started. otherwise, either a script file is run, or a pre-compiled Scala object is run. it is possible to distinguish the last two cases by using an explicit -object or -script flag, but usually the program can guess correctly.
fr fr: compiler options go first, then that lone -, or the whole thing gets confused and nobody wants that.
π ENVIRONMENT π
JAVACMDβ specify thejavacommand to be used for running the Scala code. arguments may be specified as part of the environment variable; spaces, quotation marks, etc., will be passed directly to the shell for expansion.JAVA_HOMEβ specify JDK/JRE home directory. this directory is used to locate thejavacommand unlessJAVACMDvariable set.JAVA_OPTSβ specify the options to be passed to thejavacommand defined byJAVACMD.
with Java 1.5 (or newer) one may for example configure the memory usage of the JVM as follows: JAVA_OPTS="-Xmx512M -Xms16M -Xss16M"
π EXAMPLES π
here are some examples of running Scala code, because seeing it is believing it:
- Execute a Scala program generated in the current directory:
scala hello.HelloWorld
- Execute a Scala program generated in a user-defined directory
classes:
scala -classpath classes hello.HelloWorld
- Execute a Scala program using a user-defined
javacommand:
env JAVACMD=/usr/local/bin/cacao scala -classpath classes hello.HelloWorld
- Execute a Scala program using JVM options:
env JAVACMD=java JAVA_OPTS="-Dmsg=hello -enableassertions" scala -classpath classes hello.HelloWorld
here is a complete Scala script for Unix:
#!/bin/sh
exec scala "$0" "$@"
!#
Console.println("Hello, world!")
args.toList foreach Console.println
here is a complete Scala script for MS Windows:
::#!
@echo off
call scala %0 %*
goto :eof
::!#
Console.println("Hello, world!")
args.toList foreach Console.println
if you want to use the compilation cache to speed up multiple executions of the script, then add -savecompiled to the scala command:
#!/bin/sh
exec scala -savecompiled "$0" "$@"
!#
Console.println("Hello, world!")
args.toList foreach Console.println
π¦ EXIT STATUS π¦
the scala command returns a zero exit status if it succeeds. non zero is returned in case of any error. if a script or top-level object is executed and returns a value, then that return value is passed on to scala. zero is slay, non-zero is a vibe check fail. π
π AUTHOR π
written by Martin Odersky and other members of the Scala team. legends, all of them. π
π REPORTING BUGS π
report bugs to https://issues.scala-lang.org/. she wants to hear it, bestie, tell her everything.
π COPYRIGHT π
this is open-source software, available to you under a BSD-like license. see accompanying "copyright" or "LICENSE" file for copying conditions.
there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. yes, capital-N capital-O. it's giving "i'm not responsible for your y2k-era JVM, girl." π
β SEE ALSO β
fsc(1), scalac(1), scaladoc(1), scalap(1)
and that's the whole page!! mwah. π«Ά
this was version 0.5, from April 2007, and it lives under the title scala(1). old but iconic, iykyk. bye bestie! β¨ππ¦
π¦ where this page comes from
- debian bookworm: scala 2.11.12-5 Β· BSD-3-Clause
- debian trixie: scala 2.11.12-6 Β· BSD-3-Clause
- ubuntu jammy: scala 2.11.12-5 Β· BSD-3-Clause
- ubuntu noble: scala 2.11.12-5 Β· BSD-3-Clause
- ubuntu questing: scala 2.11.12-6
- ubuntu resolute: scala 2.11.12-6build1 Β· BSD-3-Clause
- ubuntu stonking: scala 2.11.12-6build1 Β· BSD-3-Clause
- (c) 2002-2013, LAMP/EPFL #
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms