How to get absolute value of integer? abs command does not work, man pages exist - Printable Version +- Linux Lite Forums (https://www.freecinema2022.gq/forums) +-- Forum: Software - Support (https://www.freecinema2022.gq/forums/forumdisplay.php?fid=5) +--- Forum: Other (https://www.freecinema2022.gq/forums/forumdisplay.php?fid=20) +--- Thread: How to get absolute value of integer? abs command does not work, man pages exist (/showthread.php?tid=5500) |
How to get absolute value of integer? abs command does not work, man pages exist - Vera - 07-27-2018 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? Re: How to get absolute value of integer? abs command does not work, man pages exist - kpanic - 07-28-2018 Just remove the minus sign if it's there, like this: num=-4 num=$(echo $num |sed 's/\-//g') echo $num 4 Re: How to get absolute value of integer? abs command does not work, man pages exist - Vera - 07-28-2018 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. Re: How to get absolute value of integer? abs command does not work, man pages exist - kpanic - 07-28-2018 Glad to hear that [member=6960]Vera[/member] . Yes, there are many ways to do this. Happy to help |