Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install and where to install bash bc on windows

Tags:

bash

git-bash

I do not know how to install and where to install bc on windows

 $ bash -help
 GNU bash, version 4.4.23(1)-release-(x86_64-pc-msys)

 $ bc
 bash: bc: command not found

I use git-bash / mingw64 on windows.

please help

like image 392
Kuba Avatar asked Mar 13 '19 11:03

Kuba


2 Answers

GIT Bash uses MINGW compilation of GNU tools. It uses only selected ones. You can install the whole distribution of the tools from https://www.msys2.org/ and run a command to install bc. And then copy some files to installation folder of Git. This is what you do:

  1. Install before-mentioned msys2 package and run msys2 shell.
  2. Install bc using the following command: pacman -S bc
  3. Go to msys2 directory, for me it's C:\msys64\usr\bin
  4. Copy bc.exe to your Git for Windows directory, for me this is C:\Users\\AppData\Local\Programs\Git\usr\bin
like image 147
Ankush Avatar answered Oct 12 '22 20:10

Ankush


Why do you even need bc on a GIT bash?

A typical usage would be:

Prompt>echo $(1+2 | bc) // or something similar

Recently I've found out that double brackets do the thing, even without bc:

Prompt>$ echo $((1+2))
Prompt>3

Edit after first comment

In case you need floating point calculations, you might use awk, as in this example:

Prompt>awk 'BEGIN {print (20.0+5)/7}'
Prompt>3.57143

There are more examples under this URL.

like image 2
Dominique Avatar answered Oct 12 '22 20:10

Dominique