为什么我在Ruby中的反击不起作用?

use*_*147 3 ruby bash

我有这个代码

`ifconfig`

%x(ifconfig)

system("ifconfig")
Run Code Online (Sandbox Code Playgroud)

当我运行它时,只有"system("ifconfig")"工作.我知道,因为我先分开运行它们.

Chr*_*ald 6

反引号和%x变量将结果的输出返回给变量.system()将调用该命令并返回!!return_code.

1.9.3p327 :001 > `ifconfig`
 => "eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>..."

1.9.3p327 :002 > %x(ifconfig)
 => "eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>..."

1.9.3p327 :003 > system("ifconfig")
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
...
 => true
Run Code Online (Sandbox Code Playgroud)