Sometimes you are looking for a simple way to get rid of leading or tailing spaces in a string or variable. Here’s a function I usually use in my bash scripts:
function trim() { trvar=$1 trvar="${trvar#"${trvar%%[![:space:]]*}"}" trvar="${trvar%"${trvar##*[![:space:]]}"}" echo -n "$trvar" }
… where the first line is responsible for leading and the second line for trailing spaces.
To delete all spaces in a string, you can use:
# echo " this is an example " | tr -d [[:space:]]
There are some interesting points in time in this article but I don’t know if I see all of them center to heart.There is some validity but I will take hold opinion until I look into it further.Good article , thanks and we want more! Added to FeedBurner as well