Menu

Dipesh Majumdar

Blog and Paintings

How to get the absolute value of a number in shell script

August 18, 2014

Suppose you have a number A which is -10 but you need to work with the absolute value of this number. So try this code... 

#!/bin/bash
#A and B are variables below to illustrate the example
A=-10
B=${A#-}
echo " values of A, B are $A and $B"

 

Go Back

Comment