aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2019-09-20 15:48:45 +0300
committerDylan Araps <dylan.araps@gmail.com>2019-09-20 15:48:45 +0300
commit4011d6482b668433eb6edd7f5993f650703e059d (patch)
tree7f00324150ad28fa04a5f235e90e6cad99d06fc3
parenta8f03f5ddd01c8f3e42f6f4b527912a39b20eeb9 (diff)
downloadpure-sh-bible-4011d6482b668433eb6edd7f5993f650703e059d.tar.gz
pure-sh-bible-4011d6482b668433eb6edd7f5993f650703e059d.zip
docs: update
-rw-r--r--README.md22
1 files changed, 19 insertions, 3 deletions
diff --git a/README.md b/README.md
index 539728a..42ba1f3 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s
* [ARITHMETIC](#arithmetic-1)
* [Ternary Tests](#ternary-tests)
* [Check if a number is a float](#check-if-a-number-is-a-float)
+ * [Check if a number is an integer](#check-if-a-number-is-an-integer)
* [TRAPS](#traps)
* [Do something on script exit](#do-something-on-script-exit)
* [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint)
@@ -817,15 +818,30 @@ is_float() {
return 1
}
+
+```
+
+## Check if a number is an integer
+
+**Example Function:**
+
+```sh
+is_int() {
+ # usage: is_int "number"
+ case $1 in
+ *[!-0-9]*|'') return 1 ;;
+ *[0-9]*)
+ esac
+}
```
**Example Usage:**
```shell
-$ is_float 1.1 && echo true
-true
+$ is_int 1 && echo true
+$ true
-$ is_float 1 && echo true
+$ is_int 1.1 && echo true
$
```