diff options
-rw-r--r-- | README.md | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -70,6 +70,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s * [Miscellaneous](#miscellaneous) * [ARITHMETIC](#arithmetic-1) * [Ternary Tests](#ternary-tests) + * [Check if a number is a float](#check-if-a-number-is-a-float) * [TRAPS](#traps) * [Do something on script exit](#do-something-on-script-exit) * [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint) @@ -802,6 +803,32 @@ For use in `[ ]` `if [ ]; then` and `test`. var=$((var2 > var ? var2 : var)) ``` +## Check if a number is a float + +**Example Function:** + +```sh +is_float() { + # Usage: is_float "number" + case $1 in + *.*.*|*[!-.0-9]*) ;; + *[0-9].[0-9]*) return 0 + esac + + return 1 +} +``` + +**Example Usage:** + +```shell +$ is_float 1.1 && echo true +true + +$ is_float 1 && echo true +$ +``` + # TRAPS Traps allow a script to execute code on various signals. In [pxltrm](https://github.com/dylanaraps/pxltrm) (*a pixel art editor written in bash*) traps are used to redraw the user interface on window resize. Another use case is cleaning up temporary files on script exit. |