Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an `rc` file for the command line calculator `bc`?

Based on the answer to this question, I would like to default scale = 2 every time I start bc from the command line (or from inside vim). However, man bc did not mention a .bcrc file, and when I experimentally created ~/.bcrc, it did not have any noticeable effect.

Is there an environmental variable or rc file that can be set to give default options to bc?

like image 212
merlin2011 Avatar asked Mar 24 '14 21:03

merlin2011


People also ask

Which command is used for command line calculator?

bc command is used for command line calculator. It is similar to basic calculator by using which we can do basic mathematical calculations. Arithmetic operations are the most basic in any kind of programming language.

What is bc command in bash?

BC, which stands for Basic Calculator, is a command in Bash that is used to provide the functionality of a scientific calculator within a Bash script.

What is bc command?

The bc command is an interactive process that provides arbitrary-precision arithmetic. The bc command first reads any input files specified by the File parameter and then reads the standard input.


1 Answers

With GNU bc, you can set the environment variable BC_ENV_ARGS to be the name of a file that bc should read on startup.

Add the following to your .bashrc file :

export BC_ENV_ARGS=$HOME/.config/bcrc

if you need to load the standard math library, you can do this :

export BC_ENV_ARGS="-l $HOME/.config/.bcrc"

and you get a .bcrc like you wish.

like image 109
Chris Dodd Avatar answered Oct 02 '22 03:10

Chris Dodd