如何在shell脚本中的curl命令中传递变量

时间:2021-05-13 23:49:23

I have a curl command:

我有一个curl命令:

curl -u ${USER_ID}:${PASSWORD} -X GET 'http://blah.gso.woo.com:8080/rest/job-execution/job-details/${job_id}'

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:

变量job_id中有一个值,比如说1160.当我在shell中执行curl命令时,它给出了以下错误:

{"message":"Sorry. An unexpected error occured.", "stacktrace":"Bad Request. The request could not be understood by the server due to malformed syntax."}

If I pass the number '1160' directly in the command, as shown below, the curl command works.

如果我直接在命令中传递数字'1160',如下所示,curl命令有效。

curl -u ${USER_ID}:${PASSWORD} -X GET 'http://blah.gso.woo.com:8080/rest/job-execution/job-details/1160'

Can someone please help me out? I wanna be able to pass the value of the variable in the curl command.

有人可以帮帮我吗?我想能够在curl命令中传递变量的值。

1 个解决方案

#1


39  

When using variables in , 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中使用变量时,只能使用双引号,而不能使用单引号:单引号内的变量不会扩展。了解'和'与`之间的区别。请参阅http://mywiki.wooledge.org/Quotes和http://wiki.bash-hackers.org/syntax/words

#1


39  

When using variables in , 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中使用变量时,只能使用双引号,而不能使用单引号:单引号内的变量不会扩展。了解'和'与`之间的区别。请参阅http://mywiki.wooledge.org/Quotes和http://wiki.bash-hackers.org/syntax/words