In addition to creating JShell scripts in external editors, we can create them within the JShell environment as well. When taking this approach, you will need to use the /save command to save your scripts. As you can see in the following screenshot, the /save command requires, at a minimum, a file name argument:
There are three options available to you with the /save command:
- The -all option can be used to save the source of all snippets to the specified file.
- The -history option saves a sequential history of all commands and snippets you have entered since JShell was launched. JShell's ability to perform this operation informs you that it maintains a history of everything you enter.
- The -start option saves the current startup definitions to the specified file.