Why is wc -c printing spaces before the number? command: 

echo "test" | wc -c


results (7 leading spaces):

"       5"


I tested this on my linux box and I don't get the space in front of the five. is this a bug or expected behavior?
This is by design. You can see how wc pads “tabs” by removing the -c so it drops the first number in alignment with where the others would be.

You can gobble up the white space if you need with another pipe, but you should plan on this if you’re scripting things on macOS and don’t drop a different wc command down. The options are endless

echo "test" | wc -c | xargs
echo "test" | wc -c | tr -d ' '
echo "test" | wc -c | sed 's/ //g'
echo $(echo "test" | wc -c)