(Apologies in advance if my english is bad)
So, I have started studying bash, and want to make a Connect 4 game in it. However, I got stuck a bit. I have 7 arrays named column0 to column6, and I want to reference them later on.
I read in another post a few days ago, that i can use nameref to do so, but I think I'm doing something wrong, as the function runs, but doesn't do anything (doesn't check for winner). Here is a snippet form the code
declare -n nr="column$j"
for ((j=0 ; j < 6; j++ )); do
if [ "${nr[0]}" = $k ] && [ "${nr[1]}" = $k ] && [ "${nr[2]}" = $k ] && [ "${nr[3]}" = $k ]; then
(this is part of the function that will check for a winner, in case 4 characters in a row match. 'k' is just a color variable, it can be $k='Y' or $k='R')
Could someone point out what I'm doing wrong here? Or am I just dumb and Bash can't work with such solutions? Thank you in advance for any help.