How to iterate over text file having multiple-words-per-line using shell script?
问题 I know how to iterate over lines of text when the text file has contents as below: abc pqr xyz However, what if the contents of my text file are as below, abc xyz cdf pqr lmn rst and I need to get values "abc" stored to one variable and"xyz" stored to another variable. How would I do that? 回答1: If the delimiter is a space then you can do: #!/bin/bash ALLVALUES=() while read line do ALLVALUES+=( $line ) done < "/path/to/your/file" So after, you can just reference an element by ${ALLVALUES[0]}