Yes I did add the \ to the last $i
db2 connect to \$i user tester using password
But I still get the connect error.
Is there anything else I am missing...?
I wouldn't spend time trying to find things that need perl-escaping, since the end result becomes messy and hard to maintain. In stead consider moving the shell script to a (script)file and call it or move the logic in the script to perl.