'For Loop into Sed iterator wiping entire file [duplicate]

I can `sed -i 's/a/ONE/g' file.xml with no problems, but attempting to run through with a script and pass array variables wipes the entire file.

declare -a arr=("a" "b")
declare -a ray=("ONE" "TWO")

for i in "${!arr[@]}"
do
    sed -n -i 's/${arr[$i]}/${ray[$i]}/g' $file
done

Expected Output:

I should be replacing all instances of a & b, with ONE & TWO respectively.

Like I said I was able to complete this from the command line with

sed -i 's/a/ONE/g' file.xml

What gives?

EDIT:

Attempted a suggested fix using double quotes in the sed command, no luck.



Solution 1:[1]

I was able to figure out what the issue is, but not completely sure why the issue was.

The -n "Suppress Automatic Printing of Pattern Space" was for some reason sabotaging the command. If anyone has insight as to why it'd be greatly appreciated!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user7823016