Signup/Sign In
FEBRUARY 9, 2023

Arithmetic evaluation in shell (zsh: bad floating point constant)

    In the shell, the syntax $(( )) is used to evaluate an expression as an arithmetic operation. This can be useful for performing simple math operations or for setting variables based on arithmetic calculations.

    However, it is important to note that the expression inside the $(( )) must be a valid arithmetic expression, otherwise an error will be thrown.

    Testing $(( )) with Invalid Expressions

    In the example given, the user is attempting to use the $(( )) syntax with the expression github.event.inputs.environment, which is not a valid arithmetic expression. As a result, the shell returns an error message:

    zsh: bad floating point constant
    

    Similarly, attempting to use $((git.hub)) also results in an error:


    zsh: bad floating point constant

    Solving the Error

    To solve this error, it is necessary to use a valid arithmetic expression inside the $(( )) syntax. This could be as simple as using basic math operations such as addition, subtraction, multiplication, and division, or it could involve more complex calculations using variables and functions.

    For example, the following command will output the result of the arithmetic expression 1 + 1:

    echo $((1 + 1))
    


    2

    It is also possible to use variables in arithmetic expressions, as long as the variables contain numerical values. For example:

    x=5 y=10 echo $((x + y))
    


    15

    Conclusion

    In summary, the $(( )) syntax is a useful tool for evaluating arithmetic expressions in the shell. However, it is important to make sure that the expression inside the $(( )) is a valid arithmetic expression, or an error will be thrown. By using basic math operations and variables in the expression, it is possible to perform a wide range of arithmetic calculations in the shell.

    Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS