其他分享
首页 > 其他分享> > [Bash] Get value from the response

[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

标签:shell,0.1,10080,value,token,login,curl,response,Bash
来源: https://www.cnblogs.com/Answer1215/p/16307903.html