如何退出 scala 2.11.0 REPL?

在 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>
93497 次浏览

在 linux 上使用文件字符. Ctrl-D,在 Windows 上使用 Ctrl-Z

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

:quit        exit the interpreter

但我不知道 :quit在2.11.0中是否仍然存在。

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

:q

此外,exit在2.10.x 中已被弃用,建议使用 sys.exit,因此这种方法也可行:

sys.exit

顺便说一句,我认为他们这样做是为了让您能够区分在 sbt 中退出 scala 控制台和退出 sbt 本身,尽管我可能错了。

如前所述,您可以选择离开 REPL:

:quit
:q


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


sys.exit

当我在2.10.4中使用 exit时,我得到了一个警告:

警告: 有1个弃用警告; 有关详细信息,请使用-弃用重新运行

你可使用:

:q
:quit
sys.exit

它们都在2.11.x 中工作。

你可以用 系统,退出 或者 问: 退出外壳

对于 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