builtin

fc — history selection

List selected history entries with -l; -n removes numbers and -r reverses order. Without listing, fc edits and executes the selected commands; -s substitutes and executes without an editor. Review history before executing anything. This fixture lists only synthetic entries. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): printf "first\n"; printf "second\n".

Formal Syntax & Structure

bash syntaxbash
fc [-lnr] [first [last]]; fc [-e editor] [first [last]]; fc -s [old=new] [command]

Parameters & Attributes

NameTypeDescription
firststring or integerStart history entry or prefix.
laststring or integerEnd entry or prefix.
editorstringTrusted editor command for edit mode.

Return Value

exit status

Returns zero on success and nonzero on failure; option queries return zero when enabled.

Working Example

Example Snippetbash
history -chistory -s 'printf "first\n"'history -s 'printf "second\n"'fc -ln 1 2 | sed 's/^[[:space:]]*//'
Bash Reference