mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 13:13:47 -05:00
Improve array functions (#8)
This commit is contained in:
@@ -237,7 +237,7 @@ _forEachSome_() {
|
|||||||
|
|
||||||
_inArray_() {
|
_inArray_() {
|
||||||
# DESC:
|
# DESC:
|
||||||
# Determine if a value is in an array. Default is case sensitive.
|
# Determine if a regex matches an array element. Default is case sensitive.
|
||||||
# Pass -i flag to ignore case.
|
# Pass -i flag to ignore case.
|
||||||
# ARGS:
|
# ARGS:
|
||||||
# $1 (Required) - Value to search for
|
# $1 (Required) - Value to search for
|
||||||
@@ -291,12 +291,7 @@ _isEmptyArray_() {
|
|||||||
# CREDIT:
|
# CREDIT:
|
||||||
# https://github.com/labbots/bash-utility
|
# https://github.com/labbots/bash-utility
|
||||||
|
|
||||||
declare -a _array=("$@")
|
[ ${#@} -eq 0 ]
|
||||||
if [ ${#_array[@]} -eq 0 ]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_joinArray_() {
|
_joinArray_() {
|
||||||
@@ -449,7 +444,7 @@ _sortArray_() {
|
|||||||
# CREDIT:
|
# CREDIT:
|
||||||
# https://github.com/labbots/bash-utility
|
# https://github.com/labbots/bash-utility
|
||||||
|
|
||||||
[[ $# == 0 ]] && fatal "Missing required argument to ${FUNCNAME[0]}"
|
[[ $# -eq 0 ]] && fatal "Missing required argument to ${FUNCNAME[0]}"
|
||||||
declare -a _array=("$@")
|
declare -a _array=("$@")
|
||||||
declare -a _sortedArray
|
declare -a _sortedArray
|
||||||
mapfile -t _sortedArray < <(printf '%s\n' "${_array[@]}" | sort)
|
mapfile -t _sortedArray < <(printf '%s\n' "${_array[@]}" | sort)
|
||||||
|
|||||||
Reference in New Issue
Block a user