In bash, we can read an file into an array, so that each line in the file becomes an element of the array.
$ arr=( $(cat myfile) )
I was wonder how cat
works so that it allows reading a file line as an array element? Does cat
separate the file content into lines?
Does cat
not just read all the content of the file at once, without separating it into lines, so that arr
has just one single element, which is the entire content of the file? Thanks.
cat
does not care what's in the file. It make no interpretation of the data whatsoever. – Kusalananda Nov 17 '18 at 12:26