1scala(1)                         USER COMMANDS                        scala(1)
2
3
4

NAME

6       scala - Run code in the Scala 2 language
7

SYNOPSIS

9       scala  [ <option> ]... [ <torun> <argument>... ]
10

PARAMETERS

12       <compiler-option>
13              Any scalac option.  See scalac(1).
14
15       -howtorun:<how>
16              How  to execute <torun>, if it is present. Options for <how> are
17              guess (the default), script, jar, and object.
18
19       -i <file>
20              Requests that a file be pre-loaded.  It is only  meaningful  for
21              interactive shells.
22
23       -e <string>
24              Requests that its argument be executed as Scala code.
25
26       -savecompiled
27              Save this compiled version of scripts in order to speed up later
28              executions of the same script.  When running a script, save  the
29              compiled  version in a file with the same name as the script but
30              with an extension of .jar.   On  subsequent  runs  of  the  same
31              script,  the  pre-compiled .jar file will be used if it is newer
32              than the script file.
33
34       -nocompdaemon
35              Do not use the fsc offline compiler.
36
37       -nc    Same as -nocompdaemon.
38
39       -Dproperty=value
40              Set a Java system property.  If no value is specified, then  the
41              property is set to the empty string.
42
43       <torun>
44              A top-level object or a script file to run.
45
46       <argument>
47              An arguments to pass to <torun>.
48

DESCRIPTION

50       The  scala  utility  runs  Scala code using a Java runtime environment.
51       The Scala code to run is specified in one of three ways:
52
53          1.  With no arguments specified, a Scala shell starts and reads com‐
54              mands interactively.
55
56          2.  With  -howtorun:object  specified, the fully qualified name of a
57              top-level Scala object may be specified.  The object should pre‐
58              viously have been compiled using scalac(1).
59
60          3.  With  -howtorun:script  specified,  a file containing Scala code
61              may be specified.
62
63       If -howtorun: is left as the default (guess), then  the  scala  command
64       will  check  whether  a file of the specified name exists.  If it does,
65       then it will treat it as a script file; if it does not,  then  it  will
66       treat it as the name of an object.
67
68       In all three cases, arbitrary scalac options may be specified. The most
69       common option is to specify a classpath with -classpath,  but  see  the
70       scalac(1) page for full details.
71
72       If  an object is specified to run, then that object must be a top-level
73       Scala object with the specified name.  The object must define a  method
74       main with the following signature:
75
76       def main(args: Array[String]): Unit
77
78       The  method must return a Unit value, and it must accept a String array
79       as a parameter.  All arguments specified on the command  line  will  be
80       passed as arguments to the main method.
81
82       If  a  script  file  is specified to run, then the file is read and all
83       Scala statements and declarations in the file are processed  in  order.
84       Any arguments specified will be available via the argsvariable.
85
86       Script  files  may  have an optional header that is ignored if present.
87       There are two ways to format the header: either beginning with  #!  and
88       ending with !#, or beginning with ::#! and ending with ::!#.
89
90       Such  a header must have each header boundary start at the beginning of
91       a line.  Headers can be used to make stand-alone script files, as shown
92       in the examples below.
93
94       When  running a script or using -e, an already running compilation dae‐
95       mon (fsc) is used, or a new one started on demand.   The  -nocompdaemon
96       or -nc option can be used to prevent this.
97
98       If no -classpath option is specified, then scala will add ".", the cur‐
99       rent directory, to the end of the classpath.
100

OPTIONS

102       If any compiler options are specified, they must be first in  the  com‐
103       mand  line and must be followed by a bare hyphen ("-") character. If no
104       arguments are specified after the optional compiler arguments, then  an
105       interactive Scala shell is started.  Otherwise, either a script file is
106       run, or a pre-compiled Scala object is run.  It is possible to  distin‐
107       guish  the last two cases by using an explicit -object or -script flag,
108       but usually the program can guess correctly.
109

ENVIRONMENT

111       JAVACMD
112              Specify the java command to be used for running the Scala  code.
113              Arguments  may be specified as part of the environment variable;
114              spaces, quotation marks, etc., will be passed  directly  to  the
115              shell for expansion.
116
117       JAVA_HOME
118              Specify JDK/JRE home directory. This directory is used to locate
119              the java command unless JAVACMD variable set.
120
121       JAVA_OPTS
122              Specify the options to be passed to the java command defined  by
123              JAVACMD.
124
125              One  might  for  example  configure  the memory usage of the JVM
126              with: JAVA_OPTS="-Xmx2G -Xss16M"
127

EXAMPLES

129       Here are some examples of running Scala code:
130
131       Execute a Scala program generated in the current directory
132              scala hello.HelloWorld
133
134       Execute a Scala program generated in a user-defined directory classes
135              scala -classpath classes hello.HelloWorld
136
137       Execute a Scala program using a user-defined java command
138              env  JAVACMD=/usr/local/bin/cacao   scala   -classpath   classes
139              hello.HelloWorld
140
141       Execute a Scala program using JVM options
142              env JAVACMD=java JAVA_OPTS="-Dmsg=hello -enableassertions" scala
143              -classpath classes hello.HelloWorld
144
145       Here is a complete Scala script for Unix:
146
147       #!/bin/sh
148       exec scala "$0" "$@"
149       !#
150       Console.println("Hello, world!")
151       args.toList foreach Console.println
152
153       Here is a complete Scala script for MS Windows:
154
155       ::#!
156       @echo off
157       call scala %0 %*
158       goto :eof
159       ::!#
160       Console.println("Hello, world!")
161       args.toList foreach Console.println
162
163       If you want to use the compilation cache to speed  up  multiple  execu‐
164       tions of the script, then add -savecompiled to the scala command:
165
166       #!/bin/sh
167       exec scala -savecompiled "$0" "$@"
168       !#
169       Console.println("Hello, world!")
170       args.toList foreach Console.println
171

EXIT STATUS

173       The  scala  command returns a zero exit status if it succeeds. Non zero
174       is returned in case of any error.  If a script or top-level  object  is
175       executed  and  returns  a value, then that return value is passed on to
176       scala.
177

AUTHOR

179       Written by Martin Odersky and other members of the Scala team.
180

REPORTING BUGS

182       Report bugs to https://github.com/scala/bug/issues.
183
185       This is open-source software, available to you under the Apache License
186       2.0.  See accompanying "copyright" or "LICENSE" file for copying condi‐
187       tions. There is NO warranty; not even for  MERCHANTABILITY  or  FITNESS
188       FOR A PARTICULAR PURPOSE.
189

SEE ALSO

191       fsc(1), scalac(1), scaladoc(1), scalap(1)
192
193
194
195version 0.5                       April 2007                          scala(1)
Impressum