LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get absolute value of integer? abs command does not work, man pages exist
#1
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?
Using Linux Lite for everything now. I put it on my desktop and my laptop. Woohoo!
Reply
#2
Just remove the minus sign if it's there, like this:

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

echo $num
4
Reply
#3
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.
Using Linux Lite for everything now. I put it on my desktop and my laptop. Woohoo!
Reply
#4
Glad to hear that [member=6960]Vera[/member] .

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


Forum Jump:


Users browsing this thread: 2 Guest(s)