bash .bashrc 命令脚本中的 Term::ReadKey

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19840088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:31:31  来源:igfitidea点击:

Term::ReadKey in .bashrc command script

perlbashmodulecpan

提问by Moritz Petersen

I'm writing a simple motd-script in perl, that parses messages from specific websites and displays them in the center of the terminal screen.

我正在用 perl 编写一个简单的 motd 脚本,它解析来自特定网站的消息并将它们显示在终端屏幕的中央。

To get the width of the terminal I use the CPAN module Term::ReadKey.
Now I am calling this script with

为了获得终端的宽度,我使用了 CPAN 模块 Term::ReadKey。
现在我正在调用这个脚本

command /path/to/script

from my .bashrcto display it on login and opening a terminal.

从我的.bashrc登录并打开终端时显示它。

My script works fine when called while I'm logged in via perl or using

当我通过 perl 登录或使用

source .bashrc

but on the initial opening of a terminal (which is the actual purpose of the script) I'm getting this Error message:

但是在终端的初始打开(这是脚本的实际目的)时,我收到此错误消息:

Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at /path/to/perl-motd.pl line 6.
BEGIN failed--compilation aborted at /path/to/perl-motd.pl line 6.

Line 6 of the script is

脚本的第 6 行是

use Term::ReadKey;

回答by glenn Hymanman

First find where that module is installed: locate Term/ReadKey.pm

首先找到该模块的安装位置: locate Term/ReadKey.pm

If it's not found, you have to install it (may require sudo): cpan Term::ReadKey

如果未找到,则必须安装它(可能需要 sudo): cpan Term::ReadKey

If it is already installed, you have to tell Perl where it is:

如果它已经安装,你必须告诉 Perl 它在哪里:

use lib '/path/to';   # assuming it's installed as "/path/to/Term/ReadKey.pm"
use Term::ReadKey;