If you need to check any number of spaces, and not just one space, you can do this:
To cut a line of extra space (also smooths spaces in the middle and one space):
trimmed=`echo -- $original`
-- ensures that if $original contains switches that are echoed, they will still be considered normal arguments that will be echoed. It is also important not to place "" around $original , or spaces are not removed.
After that, you can simply check if $trimmed .
[ -z "$trimmed" ] && echo "empty!"
hyde Nov 22 '12 at 9:43 2012-11-22 09:43
source share