Operating system shells have long had the ability to execute a sequence of
commands saved in a text file. These script files make long sequences of
commands easier to repeatedly execute.
cmd2 supports two similar
mechanisms: command scripts and python scripts.
A command script contains a sequence of commands typed at the the prompt of a
cmd2 based application. Unlike operating system shell scripts, command
scripts can’t contain logic or loops.
Creating Command Scripts¶
Command scripts can be created in several ways:
- creating a text file using any method of your choice
- using the built-in
editcommand to create or edit an existing text file
- saving previously entered commands to a script file using
history -s. See History for more details.
If you create create a text file from scratch, just include one command per
line, exactly as you would type it inside a
Running Command Scripts¶
Command script files can be executed using the built-in
Both ASCII and UTF-8 encoded unicode text files are supported.