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: