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

2

20

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?

Refuel answered 24/3, 2014 at 21:58 Comment(0)
F
33

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.

Footed answered 24/3, 2014 at 22:17 Comment(2)
man bc - Sect. "Environment Variables": manpages.ubuntu.com/manpages/xenial/en/man1/…Novgorod
plus one for the hint to the standard math lib.Gecko
M
2

Instead of environment variables, I created an alias

alias bc="bc -l .bcrc"

and that loads the file .bcrc when I run bc.

Morphia answered 23/11, 2021 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.