Q:

Bash: Strip trailing linebreak from output

When I execute commands in Bash (or to be specific, wc -l < log.txt), the output contains a linebreak after it. How do I get rid of it?

A:

If your expected output is a single line, you can simply remove all newline characters from the output. It would not be uncommon to pipe to the 'tr' utility, or to Perl if preferred:
wc -l < log.txt | tr -d '\n'

wc -l < log.txt | perl -pe 'chomp'

You can also use command substitution to remove the trailing newline:
echo -n "$(wc -l < log.txt)"

printf "%s" "$(wc -l < log.txt)"

Please note that I disagree with the OP's decision to choose the accepted answer. I believe one should avoid using 'xargs' where possible. Yes, it's a cool toy. No, you do not need it here.

If your expected output may contain multiple lines, you have another decision to make:
If you want to remove MULTIPLE newline characters from the end of the file, again use cmd substitution:
printf "%s" "$(< log.txt)"

If you want to strictly remove THE LAST newline character from a file, use Perl:
perl -pe 'chomp if eof' log.txt

Note that if you are certain you have a trailing newline character you want to remove, you can use 'head' from GNU coreutils to select everything except the last byte. This should be quite quick:
head -c -1 log.txt

Also, for completeness, you can quickly check where your newline (or other special) characters are in your file using 'cat' and the 'show-all' flag. The dollar sign character will indicate the end of each line:
cat -A log.txt

A:

One way:
wc -l < log.txt | xargs echo -n

A:

There is also direct support for white space removal in Bash variable substitution:
testvar=$(wc -l < log.txt)
trailing_space_removed=${testvar%%[[:space:]]}
leading_space_removed=${testvar##[[:space:]]}

