如何在 Perl 程序中创建具有历史记录的 shell?

发布于 2024-08-19 10:47:55 字数 846 浏览 4 评论 0原文

我正在编写一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Spring初心 2024-08-26 10:47:55

Term::ReadLine::Gnu 是最好的模块,Term::ReadLine::Perl 后备。

Term::ReadLine::Gnu is the best module for this, Term::ReadLine::Perl the fallback.

夜访吸血鬼 2024-08-26 10:47:55

Term::ReadLine 与各种 readline 包的接口,因此将支持历史记录你描述。

Term::ReadLine interfaces to various readline packages, and as such will support history as you describe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文