I'm trying to create an array of functions in order to iterate through each function in order.
declare -a FUNCTION
FUNCTION[1]="FUNCTION.A"
FUNCTION[2]="FUNCTION.B"
FUNCTION[3]="FUNCTION.C"
for i in "${!FUNCTION[@]}"; do
${FUNCTION[$i]};
done
This just prints out FUNCTION.A and says command not found. I need it to run the function. Suggestions?
Works fine for me.
declare -a FUNCTION
FUNCTION[1]="FUNCTION.A"
FUNCTION[2]="FUNCTION.B"
FUNCTION[3]="FUNCTION.C"
#Define one of the functions
FUNCTION.A() { echo "Inside of FUNCTION.A"; }
$ for i in "${!FUNCTION[@]}"; do ${FUNCTION[$i]}; done
OUTPUT:
Inside of FUNCTION.A
FUNCTION.B: command not found
FUNCTION.C: command not found
Another way that I think looks a lot better
funcs_to_test=( voltage_force_landing voltage_warn_critical )
for testP in "${funcs_to_test[@]}"
do
$testP
done
And make sure to have written your functions above where you call this code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With