Предполагается, что используется bash:
В более общем случае, когда входные данные могут содержать произвольные символы, включая кавычки, рассмотрите возможность использования (специфичного для bas) ${var@A}
для создания назначения:
ssh root@localhost ${KEY@A} echo 'hi'
Обновление 1: справочная страница bash (версия 4.4): в операции '@A' (и других):
${parameter@operator}
Parameter transformation. The expansion is either a transformation of the value of parameter or information
about parameter itself, depending on the value of operator. Each operator is a single letter:
Q The expansion is a string that is the value of parameter quoted in a format that can be reused as input.
E The expansion is a string that is the value of parameter with backslash escape sequences expanded as with
the $'...' quoting mechansim.
P The expansion is a string that is the result of expanding the value of parameter as if it were a prompt
string (see PROMPTING below).
A The expansion is a string in the form of an assignment statement or declare command that, if evaluated,
will recreate parameter with its attributes and value.
a The expansion is a string consisting of flag values representing parameter's attributes.