使用perl检测接口名称

使用perl检测接口名称

我想检测接口名称(由于硬件原因无法使用udev)并根据它执行操作。

基本上,这应该是首先检查 wifi 设备是否能够“看到”任何东西。

代码片段:

my $interface = `/sbin/iwconfig 2>&1|grep wlan|cut -d' ' -f1`;
#upping interface
system("ifconfig $interface up");
print "my interface = $interface\n";

然而,当我尝试执行系统命令时,$interface"中似乎可能存储了一个新行。这是执行的结果。

sh: line 2: up: command not found
my interface = wlan0

Perl 版本是 5.8.3,我被迫为此使用。

我将如何存储没有 \n 的接口名称(如果这是我的错误)

手册告诉我对“系统”输出使用反引号。 Perl常见问题解答

答案1

看来你需要咀嚼$ 接口。

相关内容