docs: update

This commit is contained in:
Dylan Araps 2019-09-20 15:42:00 +03:00
parent 3988ed31be
commit a8f03f5ddd

View file

@ -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.