How to remove extra spaces in bash?
Try this: echo “$HEAD” | tr -s ” ” or maybe you want to save it in a variable: NEWHEAD=$(echo “$HEAD” | tr -s ” “) Update To remove leading and trailing whitespaces, do this: NEWHEAD=$(echo “$HEAD” | tr -s ” “) NEWHEAD=${NEWHEAD%% } NEWHEAD=${NEWHEAD## }