Working with scripts
Up to this point, you have entered data directly into JShell from the keyboard. You also have the ability to work with JShell scripts which are a sequence of JShell commands and snippets. The format is the same as other scripting formats with one command per line.
In this section, we will look at start up scripts, examine how to load scripts, how to save scripts, and then end with a look at advanced scripting with JShell.
Start up scripts
Each time the JShell is launched, the start up scripts are loaded. This also occurs each time the /reset
, /reload
, and /env
commands are used.
By default, the DEFAULT start up script is used by JShell. If you want to use a different start up script, you merely need to use the /set start <script>
command. Here is an example--/set start MyStartupScript.jsh
. Alternatively, you can use the jshell --start MyStartupScript.jsh
command at the Command Prompt to launch JShell and load the MyStartupScript.jsh
JShell start up script.
When you...