Multiple changes:

Quote variable references to avoid wildcard expansion
Use `tput cols`, falling back to $COLUMNS if that fails, falling back to 80 if that fails
    (May still fail if $COLUMNS is set to a non-number)
Fix test for valid $COLS
Use "#" if an argument is an empty string (avoids an infinite loop)