[Bash] Get value from the response

curl http://127.0.0.1:10080/login -u user

It prints out the token.

{"token":"eyJhbGciOwefewwefwIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLCJleHAiOjE2NTM2NzYzMjYsImlhdCI6MTY1MzQxNzEyNiwiaXNzIjoiYXV0aC5zZXJ2aWNlIiwic3ViIjoidXNlciJ9.G7C077LbtoL_FJF3s6wv1iMVGAiU-5zXWYpeJOnMDSY"}

You can copy and paste the long token in to the next command manually, but copying long, wrapped lines in cloud shell is broken. To work around this, you can either copy the JWT token in pieces, or - more easily - by assigning the token to a shell variable as follows

On shell 2 - login and assign the value of the JWT to a variable

TOKEN=$(curl http://127.0.0.1:10080/login -u user | jq -r '.token')

Check that it worked:

echo $TOKEN
posted @ 2022-05-25 02:35  Zhentiw  阅读(36)  评论(0编辑  收藏  举报