Unescaped variables in remote commands (like those used with SSH) are expanded locally before being sent to the remote host, leading to unexpected behavior. To ensure variables are expanded on the remote host, escape the dollar sign or use single quotes.
1
2# Noncompliant: `$HOME` expands on the client side, potentially using the wrong home directory.
3ssh user@remote "ls -l $HOME/documents"1
2# Compliant: `\$HOME` is passed literally to the remote host, expanding to the correct remote home directory.
3ssh user@remote "ls -l \$HOME/documents"