如何在 shell 脚本中的 curl 命令中传递变量 [英] How to pass a variable in a curl command in shell scripting
问题描述
我有一个 curl 命令:
I have a curl command:
curl -u ${USER_ID}:${PASSWORD} -X GET 'http://blah.gso.woo.com:8080/rest/job-execution/job-details/${job_id}'
变量 job_id
中有一个值,比如 1160.当我在 shell 中执行 curl 命令时,它给了我以下错误:
The variable job_id
has a value in it, say, 1160. When I execute the curl command in shell it gives me the following error:
{"message":"Sorry. An unexpected error occured.", "stacktrace":"Bad Request. The request could not be understood by the server due to malformed syntax."}
如果我直接在命令中传递数字1160",如下所示,curl 命令就可以工作了.
If I pass the number '1160' directly in the command, as shown below, the curl command works.
curl -u ${USER_ID}:${PASSWORD} -X GET 'http://blah.gso.woo.com:8080/rest/job-execution/job-details/1160'
我希望能够在 curl 命令中传递变量的值.
I want to be able to pass the value of the variable in the curl command.
推荐答案
当在 shell,您只能使用双引号,不能使用单引号:单引号内的变量不展开.了解 ' 和 " 和 ` 之间的区别.参见 http://mywiki.wooledge.org/Quotes 和http://wiki.bash-hackers.org/syntax/words
When using variables in shell, you can only use doubles quotes, not single quotes : the variables inside single quotes are not expanded. Learn the difference between ' and " and `. See http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words
这篇关于如何在 shell 脚本中的 curl 命令中传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!