Added read_sleep
This commit is contained in:
24
README.md
24
README.md
@@ -107,6 +107,7 @@ scripts and not full blown utilities.
|
|||||||
* [Get the current working directory.](#get-the-current-working-directory)
|
* [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)
|
* [Get the number of seconds the script has been running.](#get-the-number-of-seconds-the-script-has-been-running)
|
||||||
* [Other](#other)
|
* [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)
|
* [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)
|
* [Get the current date using `strftime`.](#get-the-current-date-using-strftime)
|
||||||
* [Bypass shell aliases.](#bypass-shell-aliases)
|
* [Bypass shell aliases.](#bypass-shell-aliases)
|
||||||
@@ -1206,6 +1207,29 @@ This is an alternative to the `pwd` built-in.
|
|||||||
|
|
||||||
# Other
|
# 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.
|
## Check if a program is in the user's PATH.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
6
test.sh
6
test.sh
@@ -121,6 +121,12 @@ test_date() {
|
|||||||
assert_equals "$result" "20"
|
assert_equals "$result" "20"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_read_sleep() {
|
||||||
|
result="$SECONDS"
|
||||||
|
read_sleep 1
|
||||||
|
assert_equals "$((result+1))" "$SECONDS"
|
||||||
|
}
|
||||||
|
|
||||||
assert_equals() {
|
assert_equals() {
|
||||||
if [[ "$1" == "$2" ]]; then
|
if [[ "$1" == "$2" ]]; then
|
||||||
((pass+=1))
|
((pass+=1))
|
||||||
|
|||||||
Reference in New Issue
Block a user