The Shell and REPL
Use the interactive shell, tab completion, history, help and the REPL.
In this lesson you will open the CommandBox interactive shell, learn the shortcuts that save typing, and try the REPL for quick experiments.
One-off commands and the shell
Every command so far started with box. That runs a single command and returns you to your normal terminal:
box version
Run box on its own to open the interactive shell:
box
Inside the shell you can drop the box prefix. These two lines do the same thing:
box version
version
Type exit (or press Ctrl-D) to leave the shell.
Tab completion
Press Tab to complete commands, namespaces and parameters. At an empty prompt, Tab lists every top level command. Keep pressing Tab to cycle through the options and press Enter to pick one.
History
Press the up arrow to step back through earlier commands. Type the start of a command first, such as cd, and the up arrow only shows history that starts with it. The history command prints everything you have run:
history
Getting help
help
help install
install help
help alone lists commands. Add a command or namespace to see its parameters and examples. Appending help to the end of a command works too.
The REPL
The repl command evaluates code line by line, and variables stay available until you exit:
repl
To run a single expression and return immediately, pass it as input:
repl input="1+1"
Inside the REPL, type exit to get back to the shell.
Recap
boxopens the shell, and inside it you can drop theboxprefix.- Tab completes, the up arrow recalls history, and
helpexplains any command. replgives you a quick code scratchpad, andrepl input="..."runs one expression.