fc

Display, edit, or re-execute commands from history.

Source: src/execution/builtins.f90:3501-3767

Synopsis

fc [-l [-nr]] [first [last]]
fc -s [old=new] [command]
fc [-e editor] [-nr] [first [last]]

Description

fc (fix command) lists history entries, opens past commands in an editor for modification, or re-executes a previous command with optional text substitution.

Options

FlagDescription
-lList history entries (don't edit)
-nSuppress line numbers in list output
-rReverse the order of listed entries
-e editorUse the specified editor
-sRe-execute with optional old=new substitution

Range Arguments

Both first and last accept:

FormMeaning
Positive integerAbsolute history number
Negative integerOffset from the end (e.g., -3 = third from last)
StringPrefix match — finds the most recent command starting with that string

Modes

List Mode (-l)

fc -l          # Last 16 commands
fc -l 10 20    # Commands 10 through 20
fc -l -5       # Last 5 commands
fc -ln         # List without line numbers
fc -lr         # List in reverse order

Edit Mode (default)

Opens commands in an editor, then executes the edited result:

fc              # Edit last command
fc -e nano      # Edit with nano
fc 42 50        # Edit commands 42-50

Editor resolution: -e argument, then $FCEDIT, then $EDITOR, then vi.

Lines starting with # or blank lines in the edited file are skipped.

Substitution Mode (-s)

Re-execute a command with an optional replacement:

fc -s                    # Re-run the last command
fc -s old=new            # Re-run last command, replacing "old" with "new"
fc -s foo=bar command    # Re-run "command" with substitution

Exit Status

StatusCondition
0Success
1Empty history, out-of-range index, substitution failed, or I/O error

See Also

  • history - Display and manage command history
  • History - Interactive history features