You are Here:
Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section



How to get absolute value of integer? abs command does not work, man pages exist

Author (Read 3991 times)

0 Members and 1 Guest are viewing this topic.

 

kpanic

  • PayPal Supporter
  • Forum Regular
  • *****
  • 162
    Posts
  • Reputation: 67
  • Linux Lite Member
    • View Profile

  • CPU: Core i5 M450

  • MEMORY: 8Gb

  • VIDEO CARD: Nvidia GT216
Glad to hear that @Vera .

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

 

Vera

  • PayPal Supporter
  • Forum Regular
  • *****
  • 140
    Posts
  • Reputation: 16
  • Enjoying Linux Lite.
    • View Profile

  • CPU: Intel Quad Core 1.6GHz

  • MEMORY: 8Gb

  • VIDEO CARD: AMD Radeon
Thanks @kpanic , 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!
 

 

kpanic

  • PayPal Supporter
  • Forum Regular
  • *****
  • 162
    Posts
  • Reputation: 67
  • Linux Lite Member
    • View Profile

  • CPU: Core i5 M450

  • MEMORY: 8Gb

  • VIDEO CARD: Nvidia GT216
Just remove the minus sign if it's there, like this:

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

echo $num
4
« Last Edit: July 28, 2018, 01:14:28 PM by kpanic »
 

 

Vera

  • PayPal Supporter
  • Forum Regular
  • *****
  • 140
    Posts
  • Reputation: 16
  • Enjoying Linux Lite.
    • View Profile

  • CPU: Intel Quad Core 1.6GHz

  • MEMORY: 8Gb

  • VIDEO CARD: AMD Radeon
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?
« Last Edit: July 28, 2018, 01:33:32 PM by Vera »
Using Linux Lite for everything now. I put it on my desktop and my laptop. Woohoo!
 

 

-->
X Close Ad

Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section