echo print newline ( \n ) no final da linha
echo abcd | xxd
0000000: 6162 6364 0a abcd.
Com algumas implementações echo , você pode usar -n :
-ndo not output the trailing newline
e teste:
echo -n abcd | wc -c
4
Com alguns outros, você precisa da sequência de escape \c :
\c: Suppress the<newline>that otherwise follows the final argument in the output. All characters following the'\c'in the arguments shall be ignored.
echo -e 'abcd\c' | wc -c
4
Portavelmente, use printf :
printf %s abcd | wc -c
4
(observe que wc -c conta bytes, não caracteres (embora no caso de abcd eles sejam geralmente equivalentes). Use wc -m para contar caracteres).