You are not logged in.
Hi,
I have an error with this syntax in bash :
#!/usr/bin/env bash
echo $((0.03*100))
It work in the terminal, but not on the script.
Do you have an idea please ?
Thanks
Last edited by SupKurtJ (2022-12-05 14:23:57)
Offline
It work in the terminal
echo $SHELL
Offline
Bash (along with most of the common *nix shells) do not handle floating point arithmetic themselves. You can use bc/cd for this - or depending on the need and source of the data, you can just change the effective units (e.g., many thermal sensors give values in thousandths of a degree - there is no decimal, so 18 degrees would be 18000; the last three digits can be trimmed or a demicimal inserted for display when printed).
Last edited by Trilby (2022-12-03 17:57:21)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Bash (along with most of the common inferior *nix shells) do not handle floating point arithmetic themselves.
ftfy, cause zsh does
Hence the inquiry on his interactive shell…
Offline
Indeed my terminal uses the zsh shell.
The script use bash.
I didn't know bash was this limitation concerning floating point arithmetic.
So either I use zsh on my script, or I use the bc package.
Thanks for your answers.
Last edited by SupKurtJ (2022-12-03 23:03:41)
Offline