I'm writting a script in Bash. In it I read a long list of names using readarray. I want to create another array with the names of the first array concatenated with ".git". That is, I have a file like this:
first
second
third
and want to have an array with data
first.git
second.git
third.git
but I get:
.gitt
.gitnd
third.git
Yes, the last one always work. If I don't use readarray but a local variable like this:
files=("first" "second" "third")
everything works. This is the minimal script that reproduces the issue:
readarray repo_names < repoNames.txt
for it in ${repo_names[@]}; do
echo "${it}.git"
done
test=("first" "second" "third")
for it in ${test[@]}; do
echo "${it}.git"
done
result:
user@debian:~/git/code/transfer$ ./tmp2.sh
.gitt
.gitnd
third.git
first.git
second.git
third.git
Why is it appending the string, overwritting it, instead of concatenating?