简体   繁体   中英

Print the output of a shell command in Perl

我想将shell命令的输出转换为变量,例如$ result,然后在屏幕上将其打印出来,例如print $ result

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'

Just use backticks, and careful with the quoting:

my $result = `df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print \$5 " " \$1 }'`;
print $result;

我本人只是一个学习者,但我发现此http://perldoc.perl.org/Shell.html有用...“此包作为展示用例提供,说明了一些Perl功能。不应使用它用于生产程序”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM