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@...
7
  • 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
    Feb 28, 2019 at 10:07
  • I also tried running with a clean environment (env -i /usr/local/bin/calc 5+5), and it gave the same result.
    – Cyberwiz
    Feb 28, 2019 at 10:10
  • Even starting a clean bash session (env -i bash --noprofile --norc) doesnt help.
    – Cyberwiz
    Feb 28, 2019 at 10:12
  • 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
    Feb 28, 2019 at 13:52
  • Switching to a different user (root) seems to help... Updated the question.
    – Cyberwiz
    Feb 28, 2019 at 13:56

2 Answers 2

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.

1
  • 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
    Mar 1, 2019 at 13:21
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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .