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
| Name | Type | Description |
|---|---|---|
| first | string or integer | Start history entry or prefix. |
| last | string or integer | End entry or prefix. |
| editor | string | Trusted 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:]]*//'