4.14.14 Command history (‘H’, ‘history’, ‘!’)

The BASH debugger can keep track of the commands you type during your debugging sessions, so that you can be certain of precisely what happened. If the prompt has not been changed (see Prompt), the history number that will be in use next is by default listed in the debugger prompt. Invalid commands and history commands are not saved on the history stack.

H [start-number [end-number]]
H [-count]
![-]n:p

You can list what is in the history stack with H. Debugger commands in the history stack are listed from most recent to least recent. If no start-number is given we start with the most recently executed command and end with the first entry in the history stack. If start-number is given, that history number is listed first. If end-number is given, that history number is listed last. If a single negative number is given list that many history commands.

An alternate form is !n:p or !-n:p where n is an integer. If a minus sign is used, n is taken as the count to go back from the end rather than as a absolute history number. In contrast H, this form only prints a single history item.

Some examples:

H      List entire history
H -2   List the last two history items
!-2:p  List a single history item starting at the same place as above
H 5    List history from history number 5 to the beginning (number 0)
H 5 0  Same as above
H 5 3  List history from history number 5 down to history number 3
!5:p   List a single history item 5
history [[-]n]
![-]n

Use this command to reexecute a given history number. If no number is given, the last debugger command in the history is executed.

An alternate form is !n or !-n where n is an integer.

If a minus sign is used in in either form, n is taken as the count to go back from the end rather than as a absolute history number.

Use these commands to manage the the BASH debugger command history facility.

set history save
set history save [ on | 1 ]

Record command history in a file, whose name may be specified with the set history filename command. By default, this option is enabled.

set history save [ off | 0 ]

Stop recording command history in a file.

set history size size

Set the number of commands which BASH keeps in its history list. This defaults to the value of the environment variable HISTSIZE, or to 256 if this variable is not set.

show history
show history save
show history size

These commands display the state of the BASH history parameters. show history by itself displays all states.

show commands

Display the last ten commands in the command history.

show commands n

Print ten commands centered on command number n.

show commands +

Print ten commands just after the commands last printed.