Adding non-integer numbers stored in variables as strings
I've been trying my hand at a bash script. If I have two variables, bob and betty, and inside bob is the string "1.55", and betty stores the string "2.40", for instance, how can I add them together and store that result in steve?
|
steve=$(( $bob + $betty ))
|
For non-integer calculations in Bash you can use bc or dc:-
Code:
steve=$(echo $bob + $betty | bc) |
Quote:
|
I stand corrected :)
Sorry about that |
All times are GMT -5. The time now is 02:37 AM. |