I am new to bash scripting and I do not understand why the following is happening. I have a script to read and store all lines of a txt file in an array. When I print out the array and add some text next to it the element seems to get overridden by the text instead of concatenated apart from the very last element.
Please see the image attached. It shows the output and the elements in the array. Each line of the txt file is an element in the array.
Thanks for any help.
#!/bin/bash
sed -i '/^[[:space:]]*$/d' video.txt
declare -a array
while read -r line;
do
array+=("$(echo "$line")")
done<video.txt
for i in "${array[@]}"
do
echo "$i and a little extra"
done