I'm trying to build an associative array in a function from a list pass in via an arg, but It just isn't working:
#!/usr/bin/env bash
function cwd {
echo "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
}
function list_commands {
local root="$1"
local command_list="${*:2}"
declare -A cmds
for cmd in $command_list; do
cmds["#{$cmd}"]+="$root/scripts/displays/$cmd.sh #{pane_current_path} #{pane_id}"
done
echo "$cmds"
}
PLUGIN_ROOT_DIR="$(cwd)"
declare -A cmds=$(list_commands "$PLUGIN_ROOT_DIR" "rbenv_ruby_ver githud")
main "$cmds"
I'm not sure what to do, bash scripting isn't my strong suit (though I'm getting better at it)
what can I do to make this work?
Bear in mind this will be executed in tmux as part of a tpm tmux plugin.
mainsomething that could see the variable? Is there a textual argument format it would accept and understand? Note that you can't justecho "$cmds"either (try it), so it's already falling over by then anyway.main, atm is just a function that (should) printout the associative array by iterating over it, but it's not important hence why it's not in the code I posted.