How to remove extra spaces in variable HEAD?
HEAD
HEAD=\" how to remove extra spaces \"
Result:>
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## }