It would be much easier to read your code if you formatted it for multiple lines. It's not good practice to concatenate multiple commands on a single line inside a script file. You should generally only do it when working in an interactive shell.
In any case, what appears to have happened is that the format of your input data has changed, and the loop isn't designed to handle that change.
[ Edit: after re-reading the OP a few times, I think I may have misunderstood the situation. I think that input now that the lines could have a filename with spaces, plus a size field? It would help if we could see what the raw input from the unzip command looks like. It could be that smallpond's answer is the correct one. ]
grail [perhaps] has the correct answer. The
read command will cram all remaining text into the last variable. So simply add another variable. One common practice is to use "
_" as a disposable variable, which has a special meaning to bash and is overwritten after each command, but you can use anything you want.
In fact, since it appears that you're only interested in the filename, you can simply re-use the disposable variable as many times as necessary to capture the unwanted fields.
Code:
SECOND_Array=()
while read -r _ _ _ filename _; do
SECOND_Array+=( "$filename" )
echo -e "$filename"
done < <(/usr/bin/unzip -c AAA_20120801.zip AAA_20120801.ctl )
(Note also that it's generally recommended to include the "
-r" option as well, in case the input data contains any backslashes.)
Another option would be to change it to use an array instead (the "
-a" option).
Code:
SECOND_Array=()
while read -r -a line; do
SECOND_Array+=( "${line[3]}" )
echo -e "${line[3]}"
done < <(/usr/bin/unzip -c AAA_20120801.zip AAA_20120801.ctl )
How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?
http://mywiki.wooledge.org/BashFAQ/001