Skip to content

Files

Latest commit

 

History

History
28 lines (17 loc) · 712 Bytes

SC2072.md

File metadata and controls

28 lines (17 loc) · 712 Bytes

Pattern: Use of decimal in shell script

Issue: -

Description

Bash and POSIX sh does not support decimals in numbers. Decimals should either be avoided, or compared using a tool that does support them.

Example of incorrect code:

[[ 2 -lt 3.14 ]]

Example of correct code:

[[ 200 -lt 314 ]]                   # Use fixed point math
[[ $(echo "2 < 3.14" | bc) == 1 ]]  # Use bc

Exceptions

If the strings happen to be version numbers and you're using <, or > to compare them as strings, and you consider this an acceptable thing to do, then you can ignore this warning.

Further Reading