Is it possible in OSX's terminal to get the length of a string? Eg:
$ echo "foo".length
Or
$ echo (cat file.txt).length
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
Try with this:
var=hello; echo ${#var}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With