You are not logged in.
I'm playing with a bash script - at a given point I need to test the lenght of a variable, and I'm using wc for this. Now
echo 12345678 | wc -m
gives 9. shouldn't be 8?
For every word I use, I noticed the result is always a number greater by one unit than the real characters' number. The same happens if I use "wc -c".
Where's the trick?
Last edited by daneel971 (2008-07-23 19:26:53)
Offline
Try this:
echo -n 12345678 | wc -m
and this
printf "%d" 12345678 | wc -m
and compare with
printf "%d\n" 12345678 | wc -m
Last edited by robertp (2008-07-23 19:22:50)
Offline
I think it's echo outputting a newline at the end, and wc counting that.
Offline
Thanks both! You hit the nail...
Offline
Also interesting: echo '12345' | hexdump -C
Offline