【问题标题】:Unable to append shell variables to curl command无法将 shell 变量附加到 curl 命令
【发布时间】:2016-04-11 03:53:58
【问题描述】:

我正在尝试将密码存储在 shell 变量中。完成此步骤后,我需要在 curl 命令中使用此密码。

logmetPassword=$(echo "XXXXXXXXXXXXX==" | openssl enc -base64 -d | openssl enc -des3 -k mysalt -d)
curl -k -XPOST -d 'user=user@bg.vnetcom&passwd=$logmetPassword&space=myspace&organization=muOrg' https://mywebsite/login

问题是,它需要$logmetPassword,因为它没有替换值。 我尝试了很多选择:

curl -k -XPOST -d 'user=user@bg.vnetcom&passwd=${logmetPassword}&  space=myspace&organization=muOrg' https://mywebsite/login
curl -k -XPOST -d 'user=user@bg.vnetcom&passwd="{$logmetPassword}"&space=myspace&organization=muOrg' https://mywebsite/login
curl -k -XPOST -d 'user=user@bg.vnetcom&passwd=\"{$logmetPassword}\"&space=myspace&organization=muOrg' https://mywebsite/log

有什么建议吗?

【问题讨论】:

    标签: bash shell variables curl


    【解决方案1】:

    如果你想替换$logmetPassword,你必须用双引号将参数(或参数的那个位)括起来。 shell 不会扩展单引号内的任何元字符。

    您可以使用以下任何一种:

    curl -k -XPOST -d "user=user@bg.vnetcom&passwd=${logmetPassword}&space=myspace&organization=muOrg" https://mywebsite/login
    curl -k -XPOST -d 'user=user@bg.vnetcom&passwd='"{$logmetPassword}"'&space=myspace&organization=muOrg' https://mywebsite/login
    

    第一个用双引号将所有内容括起来;第二个只用双引号将密码括起来。总的来说,我可能会使用第二个,但第一个对于显示的字符串是安全的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多