Wc -L reports a line-length of 8 for a tab-char. bug or feature

text processing

-L is a useful feature of wc, or so I thought. It prints the length of the longest line. For some reason it expands a single-byte tab-char to a length of 8.
Is there some way to set this to not "expand" the tab? and what might be the rationale behind this expansion?

echo -n $'\t' | wc -L

outputs 8

wc (GNU coreutils) 7.4
GNU bash, version 4.1.5

Best Answer

I find no bug report related to this, and the following lines in the source file wc.c

    case '\t':
        linepos += 8 - (linepos % 8);

seem to deliberately choose to behave in this way, probably to give an hint for width needed to display the file on screen.

A quick alternative could be

echo -n $'\t' | tr '\t' ' ' | wc -L