Added method of getting function names.

This commit is contained in:
Dylan Araps 2018-06-18 09:25:38 +10:00
parent 5f61ee3885
commit aa490304ef
2 changed files with 15 additions and 1 deletions

View File

@ -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)
* [Get the current date using `strftime`.](#get-the-current-date-using-strftime)
* [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 functions.](#bypass-shell-functions)
@ -754,7 +755,6 @@ done
shopt -u globstar
```
# File handling
**CAVEAT:** `bash` doesn't handle binary data properly in versions `< 4.4`.
@ -1520,6 +1520,15 @@ done
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.

View File

@ -139,6 +139,11 @@ test_bar() {
assert_equals "${result//$'\r'}" "[----- ]"
}
test_get_functions() {
IFS=$'\n' read -d "" -ra functions < <(get_functions)
assert_equals "${functions[0]}" "assert_equals"
}
assert_equals() {
if [[ "$1" == "$2" ]]; then
((pass+=1))