OSX terminal string length
Try with this:
var=hello; echo ${#var}
echo "foo" | wc -c
This counts the number of characters on stdin. Note that this will return 4
since echo
adds a newline at the end. Use printf
or echo -n
to avoid the added newline.
printf "foo" | wc -c