I'm trying to store the states of my terraform workspaces in an array using shell.
I'm trying this way which usually works for me:
declare -a workspace_list=( $(terraform workspace list))
for a in $(seq 0 ${#workspace_list[*]})
do
if [[ -z ${workspace_list[$a]} ]]
then
break
fi
echo $(($a+1))": "${workspace_list[$a]}
a=$(($a+1))
done
However, it gives me an output with all the files in the directory as well along with the workspaces.
I'm guessing it's to do with the multiple args with terraform command. Please help.

readarray/mapfileto populate an array with lines of a file/command output.