Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何在curl命令头部分使用变量_Bash_Shell_Curl - Fatal编程技术网

Bash 如何在curl命令头部分使用变量

Bash 如何在curl命令头部分使用变量,bash,shell,curl,Bash,Shell,Curl,我试图在curl命令的头中使用一个变量,有人能帮我找到解决方案吗 curl --location \ --request POST https://abc/bcd \ --header 'Content-Type: application/json' \ --header 'id: $empid' \ --data-raw '{ "clientName": "name",

我试图在curl命令的头中使用一个变量,有人能帮我找到解决方案吗

curl --location \
  --request POST https://abc/bcd \
  --header 'Content-Type: application/json' \
  --header 'id: $empid' \
  --data-raw '{
                    "clientName": "name",
                    "role": "dev",
                    "group": "groupid"
                    }'
在这里,我试图获取header部分中的
empid
值,但我没有获取该值,而是获取相同的变量
$empid


提前感谢。

请按以下方式重写您的脚本:

curl --location \
  --request POST https://abc/bcd \
  --header "Content-Type: application/json" \
  --header "id: $empid" \
  --data-raw "{
                    \"clientName\": \"name\",
                    \"role\": \"dev\",
                    \"group\": \"groupid\"
                    }"

如果您需要变量体系,您必须使用双引号,而不是单引号