Skip to content

Instantly share code, notes, and snippets.

@rahilwazir
Last active October 28, 2016 09:41
Show Gist options
  • Save rahilwazir/caff5cd47bab9497c29371b62017e56a to your computer and use it in GitHub Desktop.
Save rahilwazir/caff5cd47bab9497c29371b62017e56a to your computer and use it in GitHub Desktop.
Simple bash calculator
calc () {
    bc -l <<< "$@"
}

Example usage:

$ calc 65320/670
97.49253731343283582089

$ calc 65320*670
43764400

You can change this to suit yourself. For example:

divide() {
    bc -l <<< "$1/$2"
}

Note: <<< is a here string which is fed into the stdin of bc. You don't need to invoke echo.

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment