How to remove leading and trailing spaces in bash
To remove both leading and trailing spaces of a string in bash shell, you can do like following:
mytext=' This is a test '
trimed_text="$(echo -e "${mytext}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
mytext=' This is a test '
trimed_text="$(echo -e "${mytext}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"