Readline, history and bindings
Readline provides interactive editing, cursor movement, search and key bindings. It typically reads an inputrc configuration file selected by INPUTRC or default locations. bind inspects or changes Readline settings in Bash; bind -x can execute a shell command from a key sequence, so use only trusted bindings. Bash history records command text according to options such as HISTCONTROL and HISTIGNORE. HISTSIZE limits in-memory entries, HISTFILE identifies persistent storage, HISTFILESIZE limits saved history lines, and histappend chooses append rather than overwrite at normal shell exit. history -a appends new entries, history -n imports new lines, history -w writes the current list and history -r reads a file. Concurrent sessions can affect history ordering. History expansion (! forms) is separate from history storage and editing. Avoid putting tokens, passwords or sensitive data in command text; ignoring commands or clearing a list cannot guarantee deletion from other logs or sessions. The examples use synthetic history entries only, with private files. Real keypresses, Ctrl-R search and inputrc loading are manual exercises. The examples set umask 077 before writing new history files in a private directory. This does not repair permissions on pre-existing files. Check each explicit history read and write before displaying or comparing results.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Write only synthetic history
umask 077HISTFILE="$PWD/history.txt"HISTSIZE=20HISTFILESIZE=20history -c || exit 1history -s 'printf demo' || exit 1history -s 'printf example' || exit 1history -w "$HISTFILE" || exit 1cat "$HISTFILE"Expected stdout:
printf demoprintf exampleThe explicit file contains only the two supplied synthetic entries.
Limit in-memory history
umask 077HISTSIZE=2HISTFILE="$PWD/history.txt"HISTFILESIZE=20history -c || exit 1history -s first || exit 1history -s second || exit 1history -s third || exit 1history -w "$HISTFILE" || exit 1cat "$HISTFILE"Expected stdout:
secondthirdThe memory limit retains the newest two entries.
Read a known history file
umask 077printf '%s\n' 'printf alpha' 'printf beta' > seed.txt || exit 1HISTSIZE=20HISTFILESIZE=20history -c || exit 1history -r "$PWD/seed.txt" || exit 1history -w "$PWD/copy.txt" || exit 1cmp -s seed.txt copy.txt && printf 'same records\n' Expected stdout:
same recordsThe test imports text without executing it and compares the written copy.
Common mistakes
Do not treat HISTIGNORE as a secret-protection mechanism or run history -c against your everyday shell. Never copy real history into test evidence.
Practice
In a fresh private shell set HISTFILE to a new private path, add two synthetic records, write the list, and inspect only that file. Compare the purpose of HISTSIZE and HISTFILESIZE.
Next: Programmable completion