[shell] mod, div ?!!
Solved
sassoura
Posted messages
21
Registration date
Status
Membre
Last intervention
-
Anonymous user -
Anonymous user -
Hello,
How to write in shell the equivalent of the integer division operator (/ in C language) and modulo operator (% in C language) in bash?
Thank you :)
Configuration: Linux / Firefox 19.0
How to write in shell the equivalent of the integer division operator (/ in C language) and modulo operator (% in C language) in bash?
Thank you :)
Configuration: Linux / Firefox 19.0
So you provided the answer in bash...
In shell:
To store it in a shell variable:
Good luck
Think, as someone starting with Q says, to take the time to do a Google search for such simple questions; normally, you should be able to find it yourself ;-)
And especially try to ask your question more clearly next time! So I rewrote your initial message so that people who come across this thread better understand your question.
Have a good evening ;-)
expr is not a bash command.
Shells that conform to the POSIX standard can evaluate arithmetic expressions on integers without resorting to external programs, as I demonstrated, within $(( )).
At the same time, expr is part of coreutils, which is just a "necessary" package under Debian, so well... external program is a strong term, I think you should have it everywhere :-) That said, if the syntax $((...)) works in any shell, it's more concise, more readable, and cleaner...