如何从Perl获取我的路径中的程序列表?

时间:2022-05-26 06:46:01

How can I list all available UNIX commands from Perl?

如何列出Perl中所有可用的UNIX命令?

1 个解决方案

#1


perl -MFile::Find -le 'find sub {print if -f and -x _}, split ":", $ENV{PATH}'

This code looks in each directory in your path (split ":", $ENV{PATH}) for files (-f) that are executable (-x), and prints the ones it finds. You may want to read about

此代码查找路径中的每个目录(拆分“:”,$ ENV {PATH})以查找可执行文件(-f)(-x),并打印它找到的文件。你可能想读一下

An alternative that does not search subdirectories of the directories in the PATH is

不搜索PATH中目录的子目录的替代方法是

perl -le '-f and -x _ and print for map { glob "$_/*" } split ":", $ENV{PATH}'

#1


perl -MFile::Find -le 'find sub {print if -f and -x _}, split ":", $ENV{PATH}'

This code looks in each directory in your path (split ":", $ENV{PATH}) for files (-f) that are executable (-x), and prints the ones it finds. You may want to read about

此代码查找路径中的每个目录(拆分“:”,$ ENV {PATH})以查找可执行文件(-f)(-x),并打印它找到的文件。你可能想读一下

An alternative that does not search subdirectories of the directories in the PATH is

不搜索PATH中目录的子目录的替代方法是

perl -le '-f and -x _ and print for map { glob "$_/*" } split ":", $ENV{PATH}'