I'm having so much troubles trying to create a string that is the result of the concatenation of an array with a bit of addition every time it goes through the loop
# HERE IS THE VALUE OF CHANGELOG.JSON
# [
# 13,
# 14,
# 22
# ]
readarray -t lines <<<"$(cat $1/changelog.json | jq '.[]')"
echo "check if my array is filled"
echo ${lines[0]}
echo ${lines[1]}
echo ${lines[2]}
echo "my array is correctly filled.."
for i in ${!lines[@]}
do
var2="$var2 | jq '.[$((($i+1)))]=${lines[$i]}'"
echo "my var2 during loop: $var2"
done
echo "my var2 after loop $var2"
For some reasons, this script give me this as output
$ /bin/bash add-changelog.sh Blupods-front-v3/
check if my array is filled
13
14
22
my array is correctly filled..
'y var2 during loop: | jq '.[1]=13
' | jq '.[2]=14loop: | jq '.[1]=13
' | jq '.[3]=22'oop: | jq '.[1]=13
' | jq '.[3]=22'op | jq '.[1]=13
do you guys have any idea of how may i make it work ? i've already went through a lot of the solutions on stackoverflow and none of them worked (using += for concatenation) I've heard on other questions this is due to the fact that for/while loop create a subshell but even in the loop the variable doesn't get memorized.. also I don't have any pipe except for the read array at first.
EDIT: Here I add my expected result, maybe it will help you guys help me I am not trying to execute this command right away, i'm just trying to concat a string in a for loop the expected result should be this
echo $var2
| jq '.[1]=13' | jq '.[2]=14 | jq '.[3]=22'