set-option
histexpand shell option
Enables history event expansion such as !!, ordinarily enabled in interactive Bash. Expansion occurs before ordinary command execution. It can repeat a previous command, so inspect synthetic history before use. Single quotes protect literal exclamation marks. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Use interactive Bash with default key bindings; expected visible result: history-demo.
Formal Syntax & Structure
bash syntaxbash
set -o histexpand; set +o histexpandReturn Value
exit status
Returns zero on success and nonzero on failure; option queries return zero when enabled.
Working Example
Example Snippetbash
# In fresh interactive Bash, enter each line separately:set -Hprintf 'history-demo\n'!!