Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a bc output, e.g.:


echo "scale=10; BLA-BLA-HERE-NOT-IMPORTANT" | bc


96635.8038454068 days

Two Questions:

  • can the output be rounded to something like "0.3708..."?
  • can I remove the "\n"-s from the end?

I can't find any max width option in bc.

share|improve this question
up vote 3 down vote accepted

You can try something like this code:

echo "scale = 4;  3.5678/3" | bc | tr '\n' ' '

Setting scale for bc is supposed to do the rounding job. You can substitute the division part with your desired command. The output of bc is again piped to tr, which converts the newline (\n) to white space. For the above command I get the following output:

1.1892 user@localhost:~/codes$
share|improve this answer
This does not work as expected: try echo "scale=2; 2^500" | bc | tr '\n' ' ' – J. C. Leitão Jan 7 '15 at 15:06
OUT=$(echo "($BIGNUMBER+2^256)^2" | bc) ; echo $OUT
13407807929942597099574024998205846127479365820592393377723561443721\ 92709106743752503533416270312851677498564874137742504389270445080969\ 1039258113376102500

OUT=$(echo ${OUT//\\/ } | sed s#\ ##g)
echo $OUT
share|improve this answer
Wow, that's a complicated way (and originally wrong, too) of writing OUT=${OUT//$'\\\n'/}. – Gilles Feb 16 '12 at 7:06

There is an environment variable you can set called BC_LINE_LENGTH that will either disable the backslash + newline feature or will extend it. Newer versions allow you to disable it with a value of 0 like this:

BC_LINE_LENGTH=0 bc <<<"2^4096"

Older versions don't have the "0 turn off" feature and require you to set the value to a large enough value so that it doesn't affect you:

BC_LINE_LENGTH=10000 bc <<<"2^4096"

Seems like this would be a good environment variable to set in your shell if you use bc a lot and don't like the line wrapping. If you're using BASH, just place this in your .bashrc:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.