使用history命令可以在 tclsh 中查看和操作以前输入的命令。这使您可以查看先前的命令列表和重做事件。
在交互式 tclsh 中,还有一个!!
或!N
快捷方式history redo N
来重做最后输入的命令或重做命令 N(其中 N 是事件编号)。
It is not bound to up-arrow or ctrl-p or anything normal though. For that, you probably want some wrapper like rlwrap or socat READLINE
to give readline-style line editing. If you have an X Windows session, then tkcon is more use and provides reasonable command line editing. On Windows, the tclsh gets to use the builting line editing from the cmd.exe prompt - including use of uparrow to get to previous commands.
In my test session:
% info pa
8.5.13
% history z
bad option "z": must be add, change, clear, event, info, keep, nextid, or redo
% history info
1 info pa
2 history z
3 history info
% history redo 1
8.5.13
% exit
Followup
Additional comments from the original poster state that the code is not running in a standard tclsh interpreter. The history functionality is implemented in generic/tclHistory.c and the library/history.tcl library script. As noted in the C file header comment:
This module and the Tcl library file history.tcl together implement
Tcl command history. Tcl_RecordAndEval(Obj) can be called to record
commands ("events") before they are executed. Commands defined in
history.tcl may be used to perform history substitutions.
so we can deduce that the custom interpreter must use the Tcl_RecordAndEval
API call when evaluating commands that we want entered into the history. Presumably the current custom implementation is just using Tcl_Eval or one of the related functions.