Questions tagged [bc]

A good command line calculator program

Filter by
Sorted by
Tagged with
0
votes
1answer
42 views

How can some binary expressed in ASCII 0s and 1s be converted to a binary file?

I've got a PDF expressed as an ASCII file of 0s and 1s, produced in the following way: filepath="Manna.pdf" data="$((echo obase=2; hexdump -ve'/1 "%u\n"' "${filepath}") | bc | xargs printf %08i)" ...
4
votes
2answers
1k views

bc: decimal separator comma vs. point

I like using bc in interactive mode as a calculator. However, it only accepts the period (.) as decimal separator but I am using the a German keyboard layout, so I only have the comma (,) available on ...
0
votes
1answer
1k views

bc in script doesn't show decimals when dividing

I made this simple script where you're asked the dividend and the divisor, then it displays the quotient: #!/bin/bash read -p "Dividend? " dividend read -p "Divisor? " divisor if [ $divisor = "0" ...
1
vote
1answer
165 views

Ubuntu bc weird behavior

There is a weird behavior in Bash script. Trying to run following lines in two different systems. Script: cpuIdle=$(mpstat 5 1 | grep Average | awk '{ print $12 }') cpuUsage=$(bc <<< "100....
5
votes
3answers
2k views

Why doesn't `bc` utility exit with `^C`

I was using the bc utility recently and Ctrl+C cannot be used to exit the program. Ctrl+C's interrupt signal is returned with the message use quit to exit. I can use EOF (Ctrl+D) or quit to exit. I ...
8
votes
4answers
3k views

How to set default scale for bc calculator?

Ubuntu 14.04.1 LTS How do I set the default scale for the bc calculator? Each time I run bc I want scale=2 to be the default, I want to limit all calculations to 2 decimal places. I made a file in my ...
12
votes
1answer
25k views

Installing BC and any maths extension

I need to install bc (I think this is a language so I am guessing I need to install a parser but I seriously have no clue - would I need to install anything else?) onto Ubuntu 12.04 and any additional ...
15
votes
2answers
55k views

How to pass results of bc to a variable

I'm writing a script and I would like to pass the results from bc into a variable. I've declared 2 variables (var1 and var2) and have given them values. In my script I want to pass the results from ...
4
votes
3answers
3k views

Converting Celsius Processor Temperature to Fahrenheit

I'm editing a Conky theme. I would like it to output the processor temperatures in degrees Fahrenheit instead of Celsius. In the ~/.conkyrc file, the command sensors | grep 'Core 0' | cut -c18-19 is ...
55
votes
5answers
91k views

bc: set number of digits after decimal point

bc handles numbers as integers: # echo "100/3" | bc 33 bc -l handles numbers as floating point objects: # echo "100/3" | bc -l 33.33333333333333333333 Is there a way to limit the number of digits ...
45
votes
13answers
121k views

How to round decimals using bc in bash?

A quick example of what I want using bash scripting: #!/bin/bash echo "Insert the price you want to calculate:" read float echo "This is the price without taxes:" echo "scale=2; $float/1.18" |bc -l ...
11
votes
8answers
5k views

Command line calculator that keeps fractional values

I just found a good command line calculator program called bc and was satisfied with it until I discovered it rounds off fractional values, thus causing loss in precision. According to its man page: ...