Press "Enter" to skip to content

expr in Shell Script Multiplication Example

Description

In Shell, expr is known as an all-purpose expression evaluator. Command expr concatenates and assesses the arguments according to the operation given. Operations may be arithmetic, comparison, string, or logical. This tutorial explains how to use expr in a shell script for multiplication with syntax and example.

Syntax

expr expression

expr Multiplication Example

To multiply using expr command use the \* operator. The following example will do multiplication by using the \* operator with expr command.

#!/bin/bash
echo
# Multiplication Example
# ---------- ---------
echo "Multiplication Example"
echo
m=`expr 5 \* 3`
echo "5 * 3 = $m"

Output

Multiplication Example
5 * 3 = 15

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

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