解析对变量的卷曲响应,并在卷曲中使用它

我有以下脚本:

 [
  {
    "id": "d394f977-1f99-4358-80e4-fd4268c68f10","title": "Training","start": "2019-11-04T07:49:00.315Z","end": "2019-11-04T08:19:00.315Z","customer": "Kassulke - Bogisich"
  },{
    "id": "2b4d12d8-8ecd-45f6-bb4a-785a06ee3be2","title": "Private meeting","start": "2019-11-04T10:17:19.491Z","end": "2019-11-04T10:47:19.491Z","customer": "Spencer Inc"
  },{
    "id": "9650f28d-19c1-4af7-9b11-e8160a9000f7","title": "Book meeting","start": "2019-11-04T15:09:43.884Z","end": "2019-11-04T18:09:43.884Z","customer": "Wintheiser Inc"
  },{
    "id": "e7ee0f73-7c06-4c01-b432-7eccb669c767","title": "Personal meeting","start": "2019-11-04T15:11:48.587Z","end": "2019-11-04T15:41:48.587Z","customer": "Ferry,Lehner and Pollich"
  },{
    "id": "1f796db8-0c5c-40a1-bc73-ff39f669f4ce","title": "Digital meeting","start": "2019-11-04T07:55:14.155Z","end": "2019-11-04T08:55:14.155Z","customer": "Bashirian,Stanton and Fay"
  }
]

命令#!/bin/bash TOKEN=$(curl -isX POST 'http://localhost:3005/auth/tokens' \ -H 'Content-Type: application/json' \ -d '{ "name": "test@test.de","password": "1234" }' | grep X-Subject-Token | sed "s/X-Subject-Token: //g") echo $TOKEN curl --trace test.txt -X POST "http://localhost:3005/v1/users" \ -H "Content-Type: application/json" \ -H "X-Auth-token: $TOKEN" \ -d '{ "user": { "username": "alice","email": "alice@test.com","password": "test" } }' 打印正确的结果(类似35be3d05-7f80-4b11-ad20-7a7110e9d3a7)。从最近的curl请求中,我从curl中收到以下错误:

echo $TOKEN

如果我在上一个curl请求curl: (52) Empty reply from server 上方书写,则该请求正在运行。所以我猜TOKEN变量有问题。

亲切的问候

编辑: TOKEN="35be3d05-7f80-4b11-ad20-7a7110e9d3a7"的输出:

declare -p TOKEN
songweixu 回答:解析对变量的卷曲响应,并在卷曲中使用它

我不得不卸下回车证。感谢@chepner!

解决方案:

visibleCells
本文链接:https://www.f2er.com/3163784.html

大家都在问