I want to create variable from few different strings.
I am looping by some list of strings - systemvar. The next thing I want to do is to append some data (another strings) to variable created by looping the list of strings.
In this case it would be s1_bookmark_systemA, s1_bookmark_systemB and so on.
My code is:
#!/bin/bash
looping="a b"
systemvar="SystemA SystemB"
dc="s1"
for i in $looping; do
for j in $systemvar; do
line=""$i" some other variable"
echo "line: " $line
bookmark="$dc""_bookmark_""$j"
echo "created variable: " $bookmark
"${!bookmark}"+=$line ### appending to s1_bookmark_systemA, then appending to s1_bookmark_systemB and so on
echo -e "${!bookmark}"
done
done
echo $s1_bookmark_SystemA
echo $s1_bookmark_SystemB
I was assuming that would append $line to s1_bookmark_systemA as long as I am in loop. But I get:
line: a some other variable
created variable: s1_bookmark_SystemA
./tester2.sh: line 12: +=a: command not found
line: a some other variable
created variable: s1_bookmark_SystemB
./tester2.sh: line 12: +=a: command not found
line: b some other variable
created variable: s1_bookmark_SystemA
./tester2.sh: line 12: +=b: command not found
line: b some other variable
created variable: s1_bookmark_SystemB
./tester2.sh: line 12: +=b: command not found
Ideas?