mirror of
https://github.com/armbian/bash-util.git
synced 2026-01-06 10:37:49 -08:00
Added new function to variable
This commit is contained in:
30
README.md
30
README.md
@@ -23,6 +23,7 @@ Detailed documentation is available at <https://labbots.github.io/bash-utility/>
|
||||
- [Installation](#installation)
|
||||
- [Method 1 - Git Submodules](#method-1---git-submodules)
|
||||
- [Method 2 - Git Clone](#method-2---git-clone)
|
||||
- [Method 3 - Direct Download](#method-3---direct-download)
|
||||
- [Usage](#usage)
|
||||
- [Array](#array)
|
||||
- [array::contains()](#arraycontains)
|
||||
@@ -123,6 +124,7 @@ Detailed documentation is available at <https://labbots.github.io/bash-utility/>
|
||||
- [variable::is_bool()](#variableis_bool)
|
||||
- [variable::is_true()](#variableis_true)
|
||||
- [variable::is_false()](#variableis_false)
|
||||
- [variable::is_empty_or_null()](#variableis_empty_or_null)
|
||||
- [Inspired By](#inspired-by)
|
||||
- [License](#license)
|
||||
|
||||
@@ -1843,10 +1845,6 @@ Prompt yes or no question to the user.
|
||||
- **1**: If user responds with no.
|
||||
- **2**: Function missing arguments.
|
||||
|
||||
#### Output on stdout
|
||||
|
||||
- question to be prompted to the user.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
@@ -1871,7 +1869,7 @@ Prompt question to the user.
|
||||
|
||||
#### Output on stdout
|
||||
|
||||
- question to be prompted to the user.
|
||||
- User entered answer to the question.
|
||||
|
||||
#### Example
|
||||
|
||||
@@ -2450,6 +2448,28 @@ variable::is_false "false"
|
||||
0
|
||||
```
|
||||
|
||||
### variable::is_empty_or_null()
|
||||
|
||||
Check if given variable is empty or null.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- **$1** (mixed): Value of variable to check.
|
||||
|
||||
#### Exit codes
|
||||
|
||||
- **0**: If input is empty or null.
|
||||
- **1**: If input is not empty.
|
||||
|
||||
#### Example
|
||||
|
||||
```bash
|
||||
test=''
|
||||
variable::is_empty_or_null $test
|
||||
#Output
|
||||
0
|
||||
```
|
||||
|
||||
<!-- END generate_readme.sh generated SHDOC please keep comment here to allow auto update -->
|
||||
|
||||
## Inspired By
|
||||
|
||||
@@ -12,6 +12,8 @@ Options:\n
|
||||
-s | --sh-dir <folderpath> - path to the bash script source folder to generate shdocs.\n
|
||||
-l | --toc-level <number> - Minimum level of header to print in Table of Contents.\n
|
||||
-d | --toc-depth <number> - Maximum depth of tree to print in Table of Contents.\n
|
||||
-w | --webdoc - Flag to indicate generation of webdoc.\n
|
||||
-p | --dest-dir <folderpath> - Path in which wedoc files must be generated.\n
|
||||
-h | --help - Display usage instructions.\n" "${0##*/}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
# @exitcode 0 If user responds with yes.
|
||||
# @exitcode 1 If user responds with no.
|
||||
# @exitcode 2 Function missing arguments.
|
||||
#
|
||||
# @stdout question to be prompted to the user.
|
||||
interaction::prompt_yes_no() {
|
||||
[[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2
|
||||
declare def_arg response
|
||||
@@ -71,7 +69,7 @@ interaction::prompt_yes_no() {
|
||||
# @exitcode 0 If user responds with answer.
|
||||
# @exitcode 2 Function missing arguments.
|
||||
#
|
||||
# @stdout question to be prompted to the user.
|
||||
# @stdout User entered answer to the question.
|
||||
interaction::prompt_response() {
|
||||
[[ $# = 0 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2
|
||||
|
||||
|
||||
@@ -126,3 +126,19 @@ variable::is_true() {
|
||||
variable::is_false() {
|
||||
[[ "${1}" = false || "${1}" -eq 1 ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
# @description Check if given variable is empty or null.
|
||||
#
|
||||
# @example
|
||||
# test=''
|
||||
# variable::is_empty_or_null $test
|
||||
# #Output
|
||||
# 0
|
||||
#
|
||||
# @arg $1 mixed Value of variable to check.
|
||||
#
|
||||
# @exitcode 0 If input is empty or null.
|
||||
# @exitcode 1 If input is not empty.
|
||||
variable::is_empty_or_null() {
|
||||
[[ -z "${1}" || "${1}" = "null" ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user