calc command line tool always becomes interactive

1

For some reason calc always becomes interactive (as if I had specified -i, or not specified an expression at all). I have to press CTRL-C multiple times to exit.

~ calc 5+4
    9
^C
[Abort level 1]
^C
[Abort level 2]
^C
[Abort level 3]
^C
ABORT
~ 

It worked fine on my old mac. I installed it using brew (on both machines), and reinstalling calc doesnt help. What could be the reason?

Edit: I've tried starting a clean bash shell, I've checked aliases, and I've tried to use -q -e to ignore environment and configuration files. None of these things have helped.

~ type -a calc
calc is /usr/local/bin/calc

~ calc -q -e 5+4 does not change the behaviour.

~ env -i bash --noprofile --norc
bash-3.2$ calc 5+4

doesnt help either.

~ ls -l /usr/local/bin/calc
lrwxr-xr-x  1 lafp  admin  34 Feb 28 14:43 /usr/local/bin/calc -> ../Cellar/calc/2.12.7.1_1/bin/calc`

I did find something that does help. Switching to a different user! (in this case root).

~ sudo su
root@... calc 5+4
    9
root@...

Cyberwiz

Posted 2019-02-27T07:48:09.663

Reputation: 121

I have checked for aliases: calc is /usr/local/bin/calc. Did you see anything in the documentation that mentions startup files? I didnt... – Cyberwiz – 2019-02-28T10:07:34.057

I also tried running with a clean environment (env -i /usr/local/bin/calc 5+5), and it gave the same result. – Cyberwiz – 2019-02-28T10:10:28.773

Even starting a clean bash session (env -i bash --noprofile --norc) doesnt help. – Cyberwiz – 2019-02-28T10:12:23.570

I had no idea calc had startup files, sorry for not checking myself. Unfortunately -q -e didnt help (I dont have any custom startup files).

No, I meant that I got stuck in interactive mode, just as before. I have updated the question. – Cyberwiz – 2019-02-28T13:52:07.277

Switching to a different user (root) seems to help... Updated the question. – Cyberwiz – 2019-02-28T13:56:07.273

root may use different $PATH and therefore different version of calc. Investigate this. – Kamil Maciorowski – 2019-02-28T13:58:53.113

I checked, they both use /usr/local/bin/calc. – Cyberwiz – 2019-03-01T13:19:53.990

Answers

0

I think I figured it out: the problem was rvm.

In my .bash_profile I had [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

And it stayed loaded even when starting a new bash or clearing environment variables, because env -i does not clear functions, only variables.

Needless to say I will try to avoid rvm in the future... it registers hundreds of functions. Scary.

Thanks for all the help!

Cyberwiz

Posted 2019-02-27T07:48:09.663

Reputation: 121

1

Option 1:

On zsh, calc is a function. You may try that instead of /usr/local/bin/calc

$ which calc
calc () {
    awk "BEGIN{ print $* }"
}

Option 2: Try running command with absolute path. /usr/local/bin/calc 5+4 or \calc 5+4. If \calc worked for you then most probably you have set an alias for calc.

shantanoo

Posted 2019-02-27T07:48:09.663

Reputation: 111

Using a function works! Still dont understand why it is necessary but it works! Using an absolute path (or \calc) does not make any difference. – Cyberwiz – 2019-03-01T13:21:38.297