Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Shell aritmetic operations on the command line

Date: 2010-04-07 00:00:00 -0400

You can perform simple aritmetic operations on the Linux shell command line, without using any external program.

use the command expr

These are the aritmetic operations.

  • Add
  • expr 1 + 2

  • Substract
  • expr 2 - 1

  • Multiply
  • expr 2 \* 1

  • Divide
  • expr 2 / 1

  • Reminder of a divition
  • expr 20 % 3

Note that for multiplication we escape the * character, with the back slash, and that the % operand gives as the reminder of a divition, also the divition is only giving as the Integer

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.