Linux Lite Forums

Full Version: How to get absolute value of integer? abs command does not work, man pages exist
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to get the absolute value of an integer on my LL 4.0 machine. I'd like to use it in the command line. I looked up the man pages for the abs command, and it comes up there. But when I try to use the abs command, it says:
Command 'abs' not found, did you mean...
Then it lists some other things.

I'm puzzled why abs comes up in man pages but it won't work on command-line.

Anyway, the problem is, I can't find how to actually get the absolute value of an integer.  Is there a different method I should use?
Just remove the minus sign if it's there, like this:

num=-4
num=$(echo $num |sed 's/\-//g')

echo $num
4
Thanks [member=7701]kpanic[/member] , your solution worked well. Last night I did a clunkier workaround, where I tested if the number was less than zero, and if so, I subtracted the number from zero. But your solution with sed looks like it's a lot faster. It worked beautifully when I tested it today. Marking as solved.
Glad to hear that [member=6960]Vera[/member] .

Yes, there are many ways to do this. Happy to help Smile