[shell] How to add values
Solved
fabriceOb
Posted messages
23
Status
Membre
-
zipe31 Posted messages 34620 Registration date Status Contributeur Last intervention -
zipe31 Posted messages 34620 Registration date Status Contributeur Last intervention -
Hello
I'm discovering the shell in Unix (well, I'm rediscovering it, but at a level much higher than my previous knowledge)
I'm trying to add 2 "integer" values in a script. But since variables in shell are strings, I've been searching and can't find a clean solution.
nbComErr= $txtNbComErr1 + $txtNbComErr2 # => doesn't work.
nbComErr= $(expr $txtNbComErr1 + $txtNbComErr2) # => doesn't work.
echo "($txtNbComErr1 + $txtNbComErr2)" | bc # works fine, but how can I store the result in a variable
(I found a solution using a file, but I don't find that clean...)
If anyone knows, I'm open to solutions :)
I'm discovering the shell in Unix (well, I'm rediscovering it, but at a level much higher than my previous knowledge)
I'm trying to add 2 "integer" values in a script. But since variables in shell are strings, I've been searching and can't find a clean solution.
nbComErr= $txtNbComErr1 + $txtNbComErr2 # => doesn't work.
nbComErr= $(expr $txtNbComErr1 + $txtNbComErr2) # => doesn't work.
echo "($txtNbComErr1 + $txtNbComErr2)" | bc # works fine, but how can I store the result in a variable
(I found a solution using a file, but I don't find that clean...)
If anyone knows, I'm open to solutions :)
Configuration: Windows XP Firefox 1.5.0.12
4 réponses
arabesque
thanks the area
ProduPuissance4
>
arabesque
don't worry
zipe31
Posted messages
34620
Registration date
Status
Contributeur
Last intervention
6 499
>
ProduPuissance4
Since then, the water has flowed under the bridges, bash has leveled up, and the dollars ($) inside the braces have become obsolete ;-)