You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过sed在bash中向foo.sh的AMBARI_JVM_ARGS追加代理参数

How to Add Proxy JVM Arguments to AMBARI_JVM_ARGS in foo.sh

Got it, let's fix this properly. You need to insert the proxy parameters inside the quoted value of AMBARI_JVM_ARGS (not just tacked onto the end of the line) in your foo.sh file. Here are two straightforward methods:

Method 1: Manual Edit (Great for Quick, One-Off Changes)

  • Open the file with your preferred text editor, for example:
    nano foo.sh
    
  • Locate the line starting with export AMBARI_JVM_ARGS=. It’ll look like this:

    export AMBARI_JVM_ARGS="$AMBARI_JVM_ARGS -Xms512m -Xmx2048m -XX:MaxPermSize=128m -Djava.security.auth.login.config=$ROOT/etc/ambari-server/conf/krb5JAASLogin.conf -Djava.security.krb5.conf=/etc/krb5.conf -Djavax.security.auth.useSubjectCredsOnly=false"

  • Add your proxy arguments right before the closing double quote ("), like so:
    export AMBARI_JVM_ARGS="$AMBARI_JVM_ARGS -Xms512m -Xmx2048m -XX:MaxPermSize=128m -Djava.security.auth.login.config=$ROOT/etc/ambari-server/conf/krb5JAASLogin.conf -Djava.security.krb5.conf=/etc/krb5.conf -Djavax.security.auth.useSubjectCredsOnly=false -Dhttp.proxyHost=<yourProxyHost> -Dhttp.proxyPort=<yourProxyPort>"
    
  • Save and exit the editor (for nano: press Ctrl+O, hit Enter, then Ctrl+X).

Method 2: Automated Replacement with sed (Perfect for Scripts/Bulk Changes)

If you want to make this change via the command line without opening the file, use sed to modify the line in place. Replace <yourProxyHost> and <yourProxyPort> with your actual proxy details, then run:

sed -i 's/\(export AMBARI_JVM_ARGS="[^"]*\)/\1 -Dhttp.proxyHost=<yourProxyHost> -Dhttp.proxyPort=<yourProxyPort>/' foo.sh

Quick breakdown of how this works:

  • The regex \(export AMBARI_JVM_ARGS="[^"]*\) matches the start of the line up to (but not including) the closing double quote.
  • \1 refers to the matched portion, and we append the proxy arguments to it—ensuring they’re placed correctly inside the quoted string.

Verify the Change

After using either method, double-check the file to confirm the arguments are in the right spot:

grep "AMBARI_JVM_ARGS" foo.sh

You should see the proxy parameters inside the quoted value, not floating outside at the end of the line.

内容的提问来源于stack exchange,提问作者Georg Heiler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:12:59