当我进入该行时:
sed -i 's/DNS1="8.8.8.8"/DNS1="8.8.4.4"/' /etc/sysconfig/network-scripts/ifcfg-eth0
我得到了想要的结果(即 8.8.8.8 被 8.8.4.4 替换),但是,我有一个传递相同命令的 java 程序,如下所示:
public static void swapDns() throws IOException, InterruptedException
{
Runtime rt = Runtime.getRuntime();
Process ps;
String cmd[] = {"sed","-i","'s/DNS1=\"8.8.8.8\"/DNS1=\"8.8.4.4\"/'","/etc/sysconfig/network-scripts/ifcfg-eth0"};
ps = rt.exec(cmd);
}
它不起作用。它不会改变任何东西。sed/java 有问题吗,还是我遗漏了什么……