I want to read in the owner for a list of files, then compare it to the current owner and output an error if it's not the same.
I have the following, where I've replaced the comparison with a simple echo for simplicity, since it's not the comparison that's going wrong:
while IFS=' ' read -ra own; do echo ${own[@]}; done <<< $(stat -c %U file*.*)
The stat returns a string list (in this case 3 values), all with my username in this case, but the read just outputs it as a single read and string.
<myusername> <myusername> <myusername>
Clarification: I mean the the loop processes once only, returning the string with all 3 values, whereas I want 3 iterations of the loop, containing one value each.
I've changed to IFS= and IFS='\t' in case I was misreadint the output of stat in some way, but I get the same behaviour even if I just define a string like "I am here" instead of the stat command, so I'm obviously doing something else wrong.
Oh, I do need it in a one line statement as well, so if that's the problem then I guess I'm a bit screwed.
read -aassigns values in the arrayown. By using${own[@]}you get all array elements in one line. This is the correct behavior... What do you expect exactly?