Bash 脚本无法找到 perl 模块

Bash 脚本无法找到 perl 模块

我有一个未运行的 shell 脚本菜单托盘启动时i3

线路输入.i3/config

exec ~/.i3/i3-scripts/menutray.sh

这是我尝试调试的方法:

#!/bin/bash
menutray -i -u -r &>/tmp/filename

内容filename

Can't locate Linux/DesktopFiles.pm in @INC (you may need to install the Linux::DesktopFiles module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at /usr/local/bin/menutray line 28.
BEGIN failed--compilation aborted at /usr/local/bin/menutray line 28.

但我有DesktopFiles.pm

$ sudo find / -name 'DesktopFiles.pm'
/home/me/.cpan/build/Linux-DesktopFiles-0.09-LZFN3P/lib/Linux/DesktopFiles.pm
/home/me/.cpan/build/Linux-DesktopFiles-0.09-LZFN3P/blib/lib/Linux/DesktopFiles.pm
/home/me/.perl5/lib/perl5/Linux/DesktopFiles.pm

证明:

$ perl -MCPAN -e 'install Linux::DesktopFiles'
Reading '/home/me/.cpan/Metadata'
  Database was generated on Tue, 23 Feb 2016 23:41:02 GMT
Linux::DesktopFiles is up to date (0.09).

perl我的变量.bashrc

PATH="/home/me/.perl5/bin${PATH+:}${PATH}"; export PATH;
PERL5LIB="/home/me/.perl5/lib/perl5${PERL5LIB+:}${PERL5LIB}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/me/.perl5${PERL_LOCAL_LIB_ROOT+:}${PERL_LOCAL_LIB_ROOT}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/me/.perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/me/.perl5"; export PERL_MM_OPT;

有人可以帮忙吗?

答案1

您需要添加/home/me/.cpan/build到您的 perl 安装的@INC.正如您在错误消息中看到的那样,它不存在:

(@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 
/usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18
/usr/share/perl/5.18 /usr/local/lib/site_perl .)

PERL5LIB最简单的方法是在您的~/.profile(或~/.bash_profile)文件中设置:

export PERL5LIB="/home/me/.cpan/build:$PERL5LIB"

然后,获取文件 ( . ~/.profile) 或注销并重新登录。

这将允许您手动运行脚本,但当您运行 via 时它仍然不可用,.i3/config因为它可能不会读取.profile.为了确保它能够工作,请PERL5LIB在脚本本身中显式设置:

#!/bin/bash
PERL5LIB="/home/max/.cpan/build:${PERL5LIB}" menutray -i -u -r &>/tmp/filename

相关内容