【问题标题】:Can I retrieve the full history of commands from a Perl pdl2 shell (like history in bash)?我可以从 Perl pdl2 shell 中检索命令的完整历史记录(如 bash 中的历史记录)吗?
【发布时间】:2011-10-01 10:14:31
【问题描述】:

我正在使用 pdl2 shell,如何列出我的所有命令历史记录?

【问题讨论】:

    标签: perl pdl


    【解决方案1】:

    您可以在 $HOME/.perldl_hist 中找到您的历史记录

    这可能取决于是否安装了 Term::ReadLine::Gnu(我默认安装了)。

    如果您想在pdl 中访问您的历史记录,那么只需使用向上箭头键来执行前面的命令,或者输入 ^R (control-r) 然后输入您要搜索的文本(点击 ^r重复进行更远的比赛)。

    $ pdl
    perlDL shell v1.354
    ...blah blah blah...
    pdl> print 1+1
    2
    pdl> print 2+2
    4
    pdl> quit
    
    $ cat ~/.perldl_hist 
    print 1+1
    print 2+2
    $ 
    

    编辑:要从 pdl 中查找历史记录,请执行以下操作:

    $ pdl
    pdl> print join "\n", $PERLDL::TERM->GetHistory
    

    $PERLDL::TERM->GetHistory 返回当前历史记录的数组。它只是一个常规数组,所以你可以用它做任何你喜欢的事情。例如,要查找您最近所有涉及名为 mypdl 的 piddle 的直方图操作,您可以执行以下操作:

    pdl> print join "\n", grep { /histogram/ && /mypdl/ } $PERLDL::TERM->GetHistory
    

    【讨论】:

    • 谢谢。我忘记了历史文件。我想列出 pdl2 中的历史,以便在继续编码之前找出我以前做过的事情,忘记了^z cat... 的可能性。好吧,下次如果我真的想在 pdl2 中看到它,我总是可以pdl> print qx{cat ~/.perldl_hist}
    • 这种方法的问题是我想在不退出的情况下查看当前会话的历史记录!!。那可能吗?当前会话历史仅在退出后添加到 .perldl_hist 中。
    • @Pablo - 我已更新答案以从pdl 中获取信息。请注意,您必须安装 Term::ReadLine::Gnu(首选)或 Term::ReadLine::Perl
    【解决方案2】:

    来自 PDL 文档(即pdldoc perldl):

    History mechanism
      If you have the perl modules ReadLines and ReadKeys installed, then
      perldl supports a history and line-editing mechanism using editing keys
      similar to emacs. The last 500 commands are always stored in the file
      .perldl_hist in your home directory between sessions. Set
      $PERLDL::HISTFILESIZE to change the number of lines saved. The command
      "l [number]" shows you the last "number" commands you typed where
      "number" defaults to 20.
    

    【讨论】:

    • pdl2 shell 中开发计算方法后,您可以复制 .perldl_hist 文件并进行编辑以生成脚本/程序来执行相同的操作。
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2011-06-16
    • 2020-06-02
    • 2020-11-17
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多