153

在 scala (2.10.3) REPL 的最新版本中,我可以键入exit退出 REPL。但是,在 Scala 2.11.0 中这不起作用。

$ scala
Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> exit
<console>:8: error: not found: value exit
              exit
              ^

scala>
4

6 回答 6

260

我在升级时遇到了同样的问题,只需使用冒号 q。

:q

此外,exit在 2.10.x 中已弃用,sys.exit建议改为,所以这也适用:

sys.exit

作为旁注,我认为他们这样做是为了让您可以区分退出 sbt 中的 scala 控制台和退出 sbt 本身,尽管我可能是错的。

于 2014-04-22T23:51:59.103 回答
40

如之前的答案中所述,您可以选择离开 REPL:

:quit
:q

Ctrl + d // Unix
Ctrl + z // Windows

sys.exit
于 2014-04-23T08:37:28.797 回答
13

使用文件结尾字符。Ctrl-D在 Linux 上,Ctrl-Z在 Windows 上。

:help在我的 2.10.3 REPL 上使用命令可以得到这个提示:

:quit        exit the interpreter

我不知道:quit2.11.0 中是否仍然存在。

于 2014-04-22T23:50:03.787 回答
3

当我exit在 2.10.4 中使用时,我收到了警告:

警告:有 1 个弃用警告;使用 -deprecation 重新运行以获取详细信息

您可以使用:

:q
:quit
sys.exit

它们都在 2.11.x 中工作。

于 2015-03-07T16:03:34.260 回答
2

您可以使用 sys.exit OR :q 退出 shell

于 2017-08-22T14:20:32.627 回答
0

对于 sbt 1.4.1 命令,请使用以下命令

 exit:Terminates the remote client or the build when called from the console.
 shutdown:Terminates the build.

例子

vudikeri@C02CP3LAMD6M scala % sbt version 
[info] welcome to sbt 1.4.1 (N/A Java 14.0.1)

sbt:scala> shutdown
[info] shutting down sbt server
vudikeri@C02CP3LAMD6M scala % 

sbt:scala> exit
[info] shutting down sbt server
于 2020-10-22T10:16:45.763 回答