debug_echo_array
Function description
The debug_echo_array function may be used to selectively output the
contents of an array, including indices and values, to stderr and / or the
system event log.
Function parameters
$1 - The array variable to be output.
Global variables
$DEBUG - If this global variable is set then output will be sent to
stderr.
$LOGGING - If this global variable is set then output will be sent to
the system event log.
Example use
Listing 1
#! /bin/bash
# We rely on some functions from hacking-bash.sh
[[ -r ${HACKING_BASH_LIB_PATH:=/usr/lib/hacking-bash.sh} ]] && \
source ${HACKING_BASH_LIB_PATH} || \
{ echo "Unable to find ${HACKING_BASH_LIB_PATH}"; exit 1; }
# Create an example array
ARRAY[0]="zero"
ARRAY[1]="one"
ARRAY[4]="four"
# Set the DEBUG flag, we want output to the terminal
DEBUG="true"
# Use the debug_echo_array function
debug_echo_array ARRAY
max@lisa ~ $ ./debug_echo_array.shdebug: ARRAY={[0]="zero", [1]="one", [4]="four"}