Added read_sleep

This commit is contained in:
Dylan Araps 2018-06-15 17:24:12 +10:00
parent 0185f6dcab
commit c181b0afa9
2 changed files with 30 additions and 0 deletions

View File

@ -107,6 +107,7 @@ scripts and not full blown utilities.
* [Get the current working directory.](#get-the-current-working-directory)
* [Get the number of seconds the script has been running.](#get-the-number-of-seconds-the-script-has-been-running)
* [Other](#other)
* [Use `read` as an alternative to the `sleep` command.](#use-read-as-an-alternative-to-the-sleep-command)
* [Check if a program is in the user's PATH.](#check-if-a-program-is-in-the-users-path)
* [Get the current date using `strftime`.](#get-the-current-date-using-strftime)
* [Bypass shell aliases.](#bypass-shell-aliases)
@ -1206,6 +1207,29 @@ This is an alternative to the `pwd` built-in.
# Other
## Use `read` as an alternative to the `sleep` command.
I was surprised to find out `sleep` is an external command and isn't a
built-in.
**Example Funcrion:**
```sh
read_sleep() {
# Usage: sleep 1
# sleep 0.2
read -rst "${1:-1}" -N 999
}
```
**Example Usage:**
```shell
read_sleep 1
read_sleep 0.1
read_sleep 30
```
## Check if a program is in the user's PATH.
```shell

View File

@ -121,6 +121,12 @@ test_date() {
assert_equals "$result" "20"
}
test_read_sleep() {
result="$SECONDS"
read_sleep 1
assert_equals "$((result+1))" "$SECONDS"
}
assert_equals() {
if [[ "$1" == "$2" ]]; then
((pass+=1))