【问题标题】:expanding shell variable in curl POST?在 curl POST 中扩展 shell 变量?
【发布时间】:2015-03-17 15:21:07
【问题描述】:

我使用下面这行来创建数据库:

curl -X POST 'http://10.1.1.1:8086/db?u=root&p=root' -d '{name: test1}    

如果我尝试从 shell 脚本中执行此操作:

ip=10.1.1.1
curl -X POST 'http://$ip:8086/db?u=root&p=root' -d '{name: test1}'

如果我尝试在双配额内使用它们,我在单配额内替换 shell 变量时遇到问题:

curl -X POST "http://$ip:8086/db?u=root&p=root" -d '{name: test1}' 

变量扩展为正确的值,在终端打印

curl -X POST "http://10.1.21.1:8086/db?u=root&p=root" -d '{name: test1}': **No such file or directory**

这个问题的正确解决方案是什么?

【问题讨论】:

  • 也许我误读了,但您的实际问题是什么?为什么它只适用于双引号?
  • 您如何使用curl?显示脚本的相关部分。

标签: linux shell curl


【解决方案1】:

试试这个:

ip=10.1.1.1
curl -X POST 'http://'"$ip"':8086/db?u=root&p=root' -d '{name: test1}'

【讨论】:

  • 这行得通,甚至更好: curl -X POST 'http://'"$ip"':8086/db?u=root&p=root' -d '{name: test1}'
猜你喜欢
  • 2018-05-29
  • 1970-01-01
  • 2019-03-31
  • 2011-05-08
  • 2012-06-30
  • 2020-12-01
  • 1970-01-01
  • 2013-01-04
  • 1970-01-01
相关资源
最近更新 更多