The first part of the script looks like:
curl -k -X POST -H \"Content-Type: application/x-www-form-urlencoded\" -H \"Cache-Control: no-cache
First: Your token currently has literal CRs in it -- the apparent butchering is caused by those CRs being printed in your echo
output, moving the cursor back to the beginning of the line so parts of your token get overwritten with later content. To eliminate them, you can either convert the file into UNIX text format (and ensure that there aren't CRs in any of the commands generating that file), or you can use:
token=$(<token.txt) # read token.txt into "token" variable
token=${token//$'\r'/} # strip CRs from token variable
If you want to pass the Authorization header to curl
as a single word, don't end and reinitialize your quotes; keep that single argument inside one set of syntactic quotes.
-H "Authorization: AR-JWT $token"
Finally, make sure your script itself is in UNIX format -- that your editor isn't saving it with DOS newlines.