aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2019-09-20 15:42:00 +0300
committerDylan Araps <dylan.araps@gmail.com>2019-09-20 15:42:00 +0300
commita8f03f5ddd01c8f3e42f6f4b527912a39b20eeb9 (patch)
tree292ed550ad2f826c1142ef475dac07c9d781e12b
parent3988ed31beebb99d7e9ff48a056e0976c5557fe4 (diff)
downloadpure-sh-bible-a8f03f5ddd01c8f3e42f6f4b527912a39b20eeb9.tar.gz
pure-sh-bible-a8f03f5ddd01c8f3e42f6f4b527912a39b20eeb9.zip
docs: update
-rw-r--r--README.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/README.md b/README.md
index f619ad3..539728a 100644
--- a/README.md
+++ b/README.md
@@ -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.