Remove %0D from variable in BASH

rdshck picture rdshck · Nov 25, 2013 · Viewed 16k times · Source

I'm trying this:

token=`curl -I --header "X-Auth-User: [email protected]" --header "X-Auth-Key: XXXXXXXXXXXXXXXXXXXXXX" api.server.com | grep -Fi X-Auth-Token | awk -F" " '{ print $2}'`

/usr/bin/wget --accept .jpg,.jpeg -p "https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=$token" -O "image.jpg" || rm "image.jpg"

But my token result is:

https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=SERVER_018d8100000000001d1b817f7d58a6%0D

Instead of:

https://api.server.com/v1/stats/1/graph?callback=jQuery171027000000144289315_1380000003353&mnum=1&res_type=cpu&g_type=6h&graph_type=img&full=1&w=515&h=150&X-Auth-Token=SERVER_018d8100000000001d1b817f7d58a6

How to remove %0D (Carriage return)?

Answer

that other guy picture that other guy · Nov 25, 2013

You can add | tr -d '\r' to your curl pipeline to strip any carriage returns.