How to Create Shell Calculator on Ubuntu

Requirement:

  • bc package

How to:

  1. Install bc package
    $ sudo apt-get install bc
  2. Create shell script, name it ‘solve.sh’
    $ nano solve.sh

    And type in these lines:

    #!/bin/sh
    bc << EOF
    scale=4
    $@
    quit
    EOF
  3. Test the script
    $ sh solve.sh 2+2
    4
  4. Create alias ‘solve’
    $ alias solve="sh /home/user/solve.sh"
  5. Test again using alias
    $ solve 2^3
    8

Leave a Reply

Your email address will not be published. Required fields are marked *