Toda resposta aqui, até onde eu sei, não é portátil. Para uma opção portátil, considere o fc
garantido por POSIX:
$ man fc
−e editor Use the editor named by editor to edit the commands. The editor string is a utility name, subject to search via the PATH variable ... The value in the FCEDIT variable shall be used as a default when −e is not specified. If FCEDIT is null or unset, ed shall be used as the editor.
−l (The letter ell.) List the commands rather than invoking an editor on them. The commands shall be written in the sequence indicated by the first and last operands, as affected by −r, with each command preceded by the command number.
−n Suppress command numbers when listing with −l.
−r Reverse the order of the commands listed (with −l) or edited (with neither −l nor −s).
−s Re-execute the command without invoking an editor.
OPERANDS
first, last
Select the commands to list or edit. The number of previous commands that can be accessed shall be determined by the value of the HISTSIZE variable. The value of first or last or both shall be one of the following:
[+or-]number
A positive (or negative) number representing a command number; command numbers can be displayed with the −l option... For example, −1 is the immediately previous command...
When the −l option is used to list commands, the format of each command in the list shall be as follows:
"%d\t%s\n", <line number>, <command>
If both the −l and −n options are specified, the format of each command shall be:
"\t%s\n", <command>
If the consists of more than one line, the lines after the first shall be displayed as:
"\t%s\n", <continued-command>
Mas não se esqueça de usar -l ou -e se você SOMENTE deseja ver / editar seus comandos. Por padrão fc
abrirá a lista de comandos solicitada em FCEDIT (note que é diferente da variável de ambiente EDITOR ) e, quando FCEDIT é fechado, fc
executará os comandos editados.
De qualquer forma, especificamente, a resposta a esta pergunta poderia ser:
% fc -l -1
Ou sem números de linha:
% fc -ln -1
Ou os últimos cinco comandos na ordem inversa:
% fc -lrn -1 -5
No seu pager:
% fc -lrn -1 -5 |$PAGER
Para sua última chamada para fc
:
% fc -l fc