Added method of getting function names.
This commit is contained in:
11
README.md
11
README.md
@@ -127,6 +127,7 @@ scripts and not full blown utilities.
|
|||||||
* [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)
|
||||||
* [Progress bars.](#progress-bars)
|
* [Progress bars.](#progress-bars)
|
||||||
|
* [Get the list of functions from your script.](#get-the-list-of-functions-from-your-script)
|
||||||
* [Bypass shell aliases.](#bypass-shell-aliases)
|
* [Bypass shell aliases.](#bypass-shell-aliases)
|
||||||
* [Bypass shell functions.](#bypass-shell-functions)
|
* [Bypass shell functions.](#bypass-shell-functions)
|
||||||
|
|
||||||
@@ -754,7 +755,6 @@ done
|
|||||||
shopt -u globstar
|
shopt -u globstar
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# File handling
|
# File handling
|
||||||
|
|
||||||
**CAVEAT:** `bash` doesn't handle binary data properly in versions `< 4.4`.
|
**CAVEAT:** `bash` doesn't handle binary data properly in versions `< 4.4`.
|
||||||
@@ -1520,6 +1520,15 @@ done
|
|||||||
printf '\n'
|
printf '\n'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Get the list of functions from your script.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
get_functions() {
|
||||||
|
# Usage: get_functions
|
||||||
|
IFS=$'\n' read -d "" -ra functions < <(declare -F)
|
||||||
|
printf '%s\n' "${functions[@]//declare -f }"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Bypass shell aliases.
|
## Bypass shell aliases.
|
||||||
|
|
||||||
|
|||||||
5
test.sh
5
test.sh
@@ -139,6 +139,11 @@ test_bar() {
|
|||||||
assert_equals "${result//$'\r'}" "[----- ]"
|
assert_equals "${result//$'\r'}" "[----- ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_get_functions() {
|
||||||
|
IFS=$'\n' read -d "" -ra functions < <(get_functions)
|
||||||
|
assert_equals "${functions[0]}" "assert_equals"
|
||||||
|
}
|
||||||
|
|
||||||
assert_equals() {
|
assert_equals() {
|
||||||
if [[ "$1" == "$2" ]]; then
|
if [[ "$1" == "$2" ]]; then
|
||||||
((pass+=1))
|
((pass+=1))
|
||||||
|
|||||||
Reference in New Issue
Block a user