Q:

awk gsub in $0 changes variable as well

I am trying to assign the text coming in to awk to a variable, then change $0 and then output the original and the changed string:
# echo "This is a test" |awk '{text=$0; gsub(/ /,"%20"); print $text; print $0;}' 
This%20is%20a%20test
This%20is%20a%20test

But I am expecting that to return
This%20is%20a%20test
This is a test

Trying to change the #text variables does the same thing. 
# echo "This is a test" |awk '{text=$0; $text gsub(/ /,"%20"); print $text; print $0;}' 
This%20is%20a%20test
This%20is%20a%20test

GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.3, GNU MP 6.0.0) on a Synology running DSM 6.2

A:

Let's analyze your original code-line :
awk '{text=$0; gsub(/ /,"%20"); print $text; print $0;}'

text=$0: very simple you store the current record in the variable text
gsub(/ /,"%20") : this replaces all spaces with %20 in the string $0.  This is according to the POSIX standard: 

gsub(ere, repl[, in])
  Behave like sub, except that it shall replace all occurrences of the regular expression ere in $0 or in the in argument, when specified. 

It should be understood that this substitution is inplace.  Therefore $0 is now updated and different from text. 
print $text : Here is the culprit, you wish to do print text but you wrote $text.  The POSIX standard states :

Field variables shall be designated by a $ followed by a number or numerical expression. 

as you wrote $text and text is currently a string, it will try to convert the string to a number as it expects one.  As it fails, the conversion returns ZERO and this at this point $text is equivalent to $0 which represents the current record (which you previously updated with gsub). 
print $0: here you print the current record. 

In conclusion:
If you expect the following output :
This%20is%20a%20test
This is a test

The the following two awk lines give this :
awk '{text=$0; gsub(/ /,"%20",text); print text; print $0)'
awk '{text=$0; gsub(/ /,"%20"); print $0; print text }'

