I'm getting started with bash programming, and am stumbling through the syntax a little. The following is part of the code to play tic-tac-toe from the command line.
i=0
initialGrid=('_' '_' '_' '_' '_' '_' '_' '_' '_')
if [ "${ initialGrid[ $i ] }" = "_" ]; then
echo "I'm here"
fi
However I get the following error
tic.sh: line 48: ${ initialGrid[ $i ] }: bad substituion
So the echo never gets executed
I was able to substitute the above if statement and do the following without error
element=" $initialGrid[$i] "
if [ "${!element}" = "_" ]; then
echo "Element equals underscore"
fi
But again, the echo never gets execute even though i believe it clearly should