现在,JShell 随JDK 10一起发布,后来又推出了一个新版本,/exit
它采用一个可选片段作为参数。该片段被评估为将返回给调用进程的错误代码。有关详细信息,请参阅http://mail.openjdk.java.net/pipermail/kulla-dev/2017-November/002129.html。
/exit
以下是使用 jdk-10+ea-33 的新命令的帮助文本:
| Welcome to JShell -- Version 10
| For an introduction type: /help intro
jshell> /help exit
|
| /exit
|
| Leave the jshell tool. No work is saved.
| Save any work before using this command
|
| /exit
| Leave the jshell tool. The exit status is zero.
|
| /exit <integer-expression-snippet>
| Evaluate the snippet. If the snippet fails or is not an integer expression,
| display the error. Otherwise leave the jshell tool with the
| value of the expression as the exit status
jshell> /exit 123
| Goodbye (123)
JDK 9的注意事项:您不能使用/exit
非零错误代码退出 JDK 9 上的 jshell 会话。有关详细信息,请参阅https://bugs.openjdk.java.net/browse/JDK-8185840。