在cURL命令中使用环境变量 - Unix [英] Using Environment Variables in cURL Command - Unix
本文介绍了在cURL命令中使用环境变量 - Unix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题很简单。我想在cURL命令中使用环境变量类似于:
My question is very simple. I want to use environment variables in a cURL command sth similar to this:
curl -k -X POST -H 'Content-Type: application/json' -d '{"username":"$USERNAME","password":"$PASSWORD"}'
$ b b
当我运行命令$ USERNAME作为$ USERNAME字符串而不是变量的值传递给命令。是否有办法逃避这种情况?
When I run the command $USERNAME is passed to the command as a "$USERNAME" string not the value of the variable. Is there a way to escape this situation?
谢谢。
推荐答案
单引号禁止变量替换,因此使用双引号。
Single quotes inhibit variable substitution, so use double quotes. The inner double quotes must then be escaped.
... -d "{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}"
这篇关于在cURL命令中使用环境变量 - Unix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文