为什么我的Perl系统命令给我一个语法错误? [英] Why is my Perl system command giving me a syntax error?

查看:77
本文介绍了为什么我的Perl系统命令给我一个语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在脚本中无法执行包含Unix命令以grep以太网NIC的Perl脚本!我已经尝试过 qx,$ var和 system,但是它似乎不起作用!

The Perl script that contains a Unix command to grep the ethernet NICs cannot be executed within the script! I have tried "qx" , $var and "system" but it does not seem to work!

代码:

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor;

print "\nYou are now in Showing Ethernet Cards!\n\n";

print "**************************\n";
print "|Ethernet Cards Available|\n";
print "**************************\n";

print "\nThe Ethernet Cards that are available are: "; 
my $ex = system ('ifconfig | awk '{print $1}' | egrep "eth|lo"');
print "$ex";

执行错误 ./ethercards.pl第14行的语法错误,靠近’ifconfig | awk’{
由于编译错误而中止了./ethercards.pl的执行。出现在终端中。

When executed the error "syntax error at ./ethercards.pl line 14, near "'ifconfig | awk '{" Execution of ./ethercards.pl aborted due to compilation errors." shows up in the terminal.

有人对此有任何想法吗?谢谢!

Does anyone have any thoughts on this? Thanks!

推荐答案

语法突出显示还表明您的系统字符串已损坏。尝试

Syntax highlighting also suggests that your system string is broken. Try

system ('ifconfig | awk \'{print $1}\' | egrep "eth|lo"');

这篇关于为什么我的Perl系统命令给我一个语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆