Search code examples
linuxshellwc

How does the wc -c in linux work?


Why the number of characters is 4?

echo abc|wc -c

Output

4

The output should be 3, because the number of characters is 3.


Solution

  • Its also counting the newline, try

    [~]> echo -n abc|wc -c
    3
    

    -n tells the echo not to print a newline.