How to trim whitespace from bash variable?
- by too much php
I have a shell script with this code:
var=`hg st -R "$path"`
if [ -n "$var" ]; then
echo $var
fi
But the conditional code always executes because hg st always prints at least one newline character.
Is there a simple way to strip whitespace from $var (like trim() in php)?
or
Is there a standard way of dealing with this issue?
I could use sed or awk, but I'd like to think there is a more elegant solution to this problem.