I wrote this code to loop through usernames and domains on my LAN. Sadly, the script prints nothing.
#!/bin/bash
construct_array_of_trgts() {
declare -A usrs_n_dmns
local -a guest_dmns
local -a usrs=("j" "jim" "o" "root")
local -a guest_dmns=("raspberrypi" "lenovo")
for d in "${guest_dmns[@]}"; do
PS3="Select the users to include for sshing into $d. Q when done selecting."$'\n'
local -a targt_usrs
select u in "${usrs[@]}"; do
if [[ "$u" ]]; then
targt_usrs+=("$u")
elif [[ "$REPLY" == 'q' ]]; then
break;
fi
done
usrs_n_dmns["${d}"]="$targt_usrs"
done
}
construct_array_of_trgts
for d in "${!usrs_n_dmns[@]}"; do
targt_usrs=("${usrs_n_dmns["${d}"]}")
echo "$usrs_n_dmns"
for u in "${targt_usrs[@]}"; do
echo "ssh ${u}@${d}"
done
done
Why doesn't this script print anything visible? Is it at all possible for an array to be a value in an associative array in Bash?
foo, for example, essentially lets you createfoo[0],foo[1], etc, as individual "names", as well as some special names (foo[@], e.g.) that will expand to all the values assigned to the special indexed names.