In a script, I tried to assign a session token string to a variable, that token string was stored in a text file.
SESSION_TOKEN=$(<login_token.txt)
Previously, I did the assignment by writing literally.
SESSION_TOKEN_ORIGINAL=eyJhbGciOiJI......CGHyYuRs
As the session token is different every time I start a session, I store the obtained token in a text file instead of editing the bash script every time.
Unexpectedly, SESSION_TOKEN was not accepted by the server, while SESSION_TOKEN_ORIGINAL worked.
I used bash to invoke the script
bash ./myscript.bash
To understand the reason, I created an experimental comparison statement
if [ "$SESSION_TOKEN" == "$SESSION_TOKEN_ORIGINAL" ]
then
echo "two tokens are the same"
fi
It does NOT output the equal statement. Why?
To better illustrate the context, I post the entire script with the server address masked.
#!/bin/bash
SESSION_TOKEN=$(<./login_token.tmp)
SESSION_TOKEN_ORIGINAL=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkdXIiOjI
USERID=fsag25fea
curl -s -X GET -H "x-tidepool-session-token: $SESSION_TOKEN" -H "Content-Type: application/json" "https://api.database.org/metadata/users/$USERID/users" #this does not work, the server responds with 0 content
curl -s -X GET -H "x-tidepool-session-token: $SESSION_TOKEN_ORIGINAL" -H "Content-Type: application/json" "https://api.database.org/metadata/users/$USERID/users" #this works, the server responds with the expected json