Using the following code, I'm trying to read a file into an array:
GROUPS=() while IFS=: read -r g1 g2 g3 g4 do GROUPS+=("$g3") echo "$g3" done < /etc/group This doesn't work, it doesn't even output anything, however, if I leave only the echo it does print the contents of the file. As long as the instruction to add to an array is present somewhere in the loop, nothing is printed. It seems very strange since I can do this to other files without problems.
Any idea what's causing this? I checked with bash -x and when the problematic instruction is present, it doesn't even enter the loop.
Also, in case it is relevant, I'm running this as root.