Well, the construct loops while there is a $ in "$tmpdir". It breaks
out of the loop when there isn't. That's quite straightforward. The
sed command replaces the three characters \ ` " with \ followed by the
characters. That gives an additional level of quoting which the eval
(which is there for expanding $ until none is left) then strips again.
It would be interesting to see what happens on the system where it
fails. One thing that might help is writing
's/[\\`"-"]/
instead, doubling the initial \ in case sed misinterprets the range (I
am not sure why we have "-" instead of just ", probably to stop syntax
highlighting from going complete bonkers).