我正在运行 sed 命令以将字符串添加到文件中的一行:这是原始行:
export JAVA_TOOL_OPTIONS="-Doption=Xyz"
它将更新为:
export JAVA_TOOL_OPTIONS="-Djava.net.useSystemProxies=false -Dhttp.nonProxyHosts=.abc.com|.abc1.com|localhost -Dhttps.proxyPort=443 -Doption=Xyz"
这是命令:
sed -i '1 s/export JAVA_TOOL_OPTIONS="/export JAVA_TOOL_OPTIONS="-Djava.net.useSystemProxies=false -Dhttp.nonProxyHosts=.abc.com|.abc1.com|localhost -Dhttps.proxyPort=443 /1 ' startup.sh
当它在服务器的命令行上运行时,这工作正常。但是,当它通过 SSH 完成时它无法运行:
ssh @hostname 'sed -i '1 s/export JAVA_TOOL_OPTIONS="/export JAVA_TOOL_OPTIONS="-Djava.net.useSystemProxies=false -Dhttp.nonProxyHosts=.abc.com|.abc1.com|localhost -Dhttps.proxyPort=443 /1 ' startup.sh'
我相信它与“|”有关。我什至尝试使用3个反冲:
ssh @hostname 'sed -i '1 s/export JAVA_TOOL_OPTIONS="/export JAVA_TOOL_OPTIONS="-Djava.net.useSystemProxies=false -Dhttp.nonProxyHosts=.abc.com\\\|.abc1.com\\\|localhost -Dhttps.proxyPort=443 /1 ' startup.sh'
我替换了 | 有 3 次反弹:
ssh @hostname 'sed -i '1 s/export JAVA_TOOL_OPTIONS="/export JAVA_TOOL_OPTIONS="-Djava.net.useSystemProxies=false -Dhttp.nonProxyHosts=.abc.com\\\.abc1.com\\\localhost -Dhttps.proxyPort=443 /1 ' startup.sh'
仍然失败。知道我做错了什么吗?
ssh @hostname "$(cat <<'EOT'
sed -i ... # your command, verbatim
EOT
)"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句