Just remove the minus sign if it's there, like this:
num=-4
num=$(echo $num |sed 's/\-//g')
echo $num
4
num=-4
num=$(echo $num |sed 's/\-//g')
echo $num
4
How to get absolute value of integer? abs command does not work, man pages exist
|
« Next Oldest | Next Newest »
|
Messages In This Thread |
How to get absolute value of integer? abs command does not work, man pages exist - by Vera - 07-27-2018, 11:14 PM
Re: How to get absolute value of integer? abs command does not work, man pages exist - by kpanic - 07-28-2018, 04:06 PM
Re: How to get absolute value of integer? abs command does not work, man pages exist - by Vera - 07-28-2018, 05:32 PM
Re: How to get absolute value of integer? abs command does not work, man pages exist - by kpanic - 07-28-2018, 05:47 PM
|