5

Why wc -m counts one character (symbol) more from here-string (<<<)

Here is example:

$ TEST_STR="askubuntu"
$ echo "$TEST_STR"
askubuntu
$ wc -m <<<"$TEST_STR"
10

It is saying 10, but actually there is only 9 symbols.

The same problem appears for wc -c

1 Answer 1

8

Because Bash Here strings add trailing newline character.

Here is proof:

$ TEST_STR="askubuntu"
$ echo "$TEST_STR"
askubuntu
$ od -c <<<"$TEST_STR"
0000000   a   s   k   u   b   u   n   t   u  \n
0000012

Also, there is a few nice answers that explains why newline character should be there:

  1. Why here string add newline character?
  2. Why new line character should be there?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .