一旦插入的文本不是最后一个参数,如何在 shell 脚本的 wget 命令中使用heredoc?

一旦插入的文本不是最后一个参数,如何在 shell 脚本的 wget 命令中使用heredoc?

我的问题:测试应用程序时,我使用 wget 将 JSON 发送到本地 Tomcat。

总结一下命令:

wget --header='...' --post-data='LONG_JSON' -q0 URL

扩展命令:

wget --header='Content-Type:application/json' --post-data='{"foocao": 0, "foorio": { "foo": "foofoofoo", "foofooe": "foofoo", "foon": "fooe", "fool": "foo.com", "fooa": "foofoo" }, "fooade": { "foofoofoo": "foofoo-foo-foo-foo-foofoofoo", "foo": "fooTE", "fool": "baa.com", "foofoo": "foo9-foo", "fooao": "foofoo", "fooor": "foofoo", "foofoo": "foofooia", "foofooo": "fooo", "foos": "✓ foofooade e foofooe;✓ foofooa, foofooação fooal e Polífoo e foofoo foonil;✓ foofoo e foor;✓ foofoofoo, foofoo e fooa;✓ foofooção e foofooe de fooessão;✓ Saúde;✓ fooura;✓ fooação;✓ fooitório e foofoode; foofoofoofoo e foo foofoo;✓ foo", "foo": "www.foo.com", "foodo": "aa", "foode": "foo", "foofoo": "foo", "foofoonto": "", "fooro": "1", "cep": "foofoo", "foofooo": "Bla, foola fooa"} }'  -qO- http://foo/jspui/foo.jsp

如何替代长json使用特雷多克在 shell 脚本文件中?

答案1

LONG_JSON=$(cat <<EOT
{
  "foocao": 0,
  "foorio":
  {
    "foo": "foofoofoo",
    "foofooe": "foofoo",
    "foon": "fooe",
    "fool": "foo.com",
    "fooa": "foofoo"
  },
  "fooade":
  {
    "foofoofoo": "foofoo-foo-foo-foo-foofoofoo",
    "foo": "fooTE",
    "fool": "baa.com",
    "foofoo": "foo9-foo",
    "fooao": "foofoo",
    "fooor": "foofoo",
    "foofoo": "foofooia",
    "foofooo": "fooo",
    "foos": "✓ foofooade e foofooe;✓ foofooa, foofooação fooal e Polífoo e foofoo foonil;✓ foofoo e foor;✓ foofoofoo, foofoo e fooa;✓ foofooção e foofooe de fooessão;✓ Saúde;✓ fooura;✓ fooação;✓ fooitório e foofoode; foofoofoofoo e foo foofoo;✓ foo",
    "foo": "www.foo.com",
    "foodo": "aa",
    "foode": "foo",
    "foofoo": "foo",
    "foofoonto": "",
    "fooro": "1",
    "cep": "foofoo",
    "foofooo": "Bla, foola fooa"
  }
}
EOT
)
wget --header='Content-Type:application/json' --post-data="$LONG_JSON" -qO- http://foo/jspui/foo.jsp

相关内容