如何在 Perl 程序中创建具有历史记录的 shell?
我正在编写一个在 Perl 中作为 shell 执行的工具。我希望它有历史记录,这样如果您按向上箭头,您就会返回到上一个命令,就像 bash 或其他 shell 一样。我该怎么办?
-- 编辑 --
感谢 daxim 将我引向 Term::ReadLine::Gnu。我能够让它在我的 Linux 机器上工作,这正是我所寻找的。然而,我的主要开发机器正在运行 OS X。当我尝试安装该模块时,我收到此错误:
~/Downloads/Term-ReadLine-Gnu-1.19 > perl Makefile.PL
Found `/usr/lib/libtermcap.dylib'.
gcc-4.2 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include - DHAVE_STRING_H rlver.c -o rlver -arch i386 -arch ppc -L/usr/local/lib -lreadline -ltermcap
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The libreadline you are using is the libedit library. Use the GNU Readline Library.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
我目前正在通过 Google 结果解决此问题,但如果有人以前见过此问题并有指示,那么将不胜感激。谢谢!
I'm writing a tool that is executed as a shell in Perl. I want it to have a history, so that if you press the up arrow, you go back to the previous command, just like bash or other shells. How should I go about this?
-- EDIT --
Thanks to daxim for pointing me towards Term::ReadLine::Gnu. I was able to get it to work on my Linux box and it's exactly what I was looking for. However, my main dev machine is running OS X. When I try to install the module, I get this error:
~/Downloads/Term-ReadLine-Gnu-1.19 > perl Makefile.PL
Found `/usr/lib/libtermcap.dylib'.
gcc-4.2 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include - DHAVE_STRING_H rlver.c -o rlver -arch i386 -arch ppc -L/usr/local/lib -lreadline -ltermcap
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The libreadline you are using is the libedit library. Use the GNU Readline Library.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I am currently making my way through the Google results for this problem, but if anyone has seen this before and has pointers, that would be much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Term::ReadLine::Gnu 是最好的模块,Term::ReadLine::Perl 后备。
Term::ReadLine::Gnu is the best module for this, Term::ReadLine::Perl the fallback.
Term::ReadLine 与各种 readline 包的接口,因此将支持历史记录你描述。
Term::ReadLine interfaces to various readline packages, and as such will support history as you describe.