Table of Contents

Bash - fc (Fix Command) - Range of command from history - (builtin)

About

Fix Command (fc) is a builtin command that retrieve a range of commands from first to last is selected from the history list.

Syntax

First form

fc has two modes:

fc [-e ename] [-nlr] [first] [last]

where:

If neither variable is set, is used. When editing is complete, the edited commands are echoed and executed.

First and last

Editor

If ename is not given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT is not set.

see Linux - Shell Editor

Example

Second form

Command is re-executed after each instance of pat is replaced by rep.

fc -s [pat=rep] [cmd]

A useful alias to use with this is ‘‘r=“fc -s”’’, so that typing ‘‘r cc’’ runs the last command beginning with ‘‘cc’’ and typing ‘‘r’’ re-executes the last com- mand.

If the first form is used, the return value is 0 unless an invalid option is encountered or first or last specify history lines out of range. If the -e option is supplied, the return value is the value of the last command executed or failure if an error occurs with the temporary file of commands. If the second form is used, the return status is that of the command re-exe- cuted, unless cmd does not specify a valid history line, in which case fc returns failure.

Documentation / Reference