I'm trying to declare and append to an array in a bash script, after searching i resulted in this code.
list=()
list+="string"
But when i echo this out it results in nothing. I have also tried appending to the array like this
list[$[${#list[@]}+1]]="string"
I don't understand why this is not working, anyone have any suggestions?
EDIT: The problem is list is appended to inside a while loop.
list=()
git ls-remote origin 'refs/heads/*' | while read sha ref; do
list[${#list[@]}+1]="$ref"
done
declare -p list
see stackoverflow.com/q/16854280/1126841