I have a file which is created with
touch hello
echo "apple" >> hello
echo "pear" >> hello
echo "pineapple" >> hello
And I'd like to convert this hello file into an array line by line in bash. I.e. the desired array should have
echo ${arr[1]} // apple
echo ${arr[2]} // pear
echo ${arr[3]} // pineapple
I tried
ARR=( )
function test() {
fileItemString=$(cat hello |tr "\n" " ")
ARR+=($fileItemString)
}
test
But it just saves the whole file into the first element of ARR.