This is a common miss-conception about how many/most programming languages work.
In imperative languages (bash/C/Java/python....), the = operator does not work the same way as in maths.
a=1 means put 1 into a (overwriting what was there).
I.E.
var1=1 # var1 ← 1 #overwrite var1 with 1 var2=$var1 # var2 ← $var1 #overwrite var2 with evaluation of $var1 (i.e 1) var1=2 # var1 ← 2 #overwrite var1 with 2 stdout ←← $var2 #append $var2 to stdout
Therefore
# var1 var2 var1=1 # 1 n/a var2=$var1 # 1 1 var1=2 # 2 1