如何通过ssh将echo的输出重定向到文件
我正在尝试通过ssh将变量的内容重定向到文件.像:
I'm trying to redirect content of a variable to a file through ssh. like:
ssh $MachineIP echo $CM_Config > $mName/CM_CONFIG
其中,$CM_Config
是主机中包含多行的本地变量,而$mName/CM_CONFIG
位于$MachineIP
中
假设我的ssh配置正确,我应该如何将本地变量重定向到远程文件.
预先感谢
where $CM_Config
is a local variable in my host containing multiple line, and $mName/CM_CONFIG
is located in $MachineIP
how should I redirect local variable to the remote file assuming my ssh configurations are correct.
Thanks in advance
对于我来说,此命令解决了问题:
In my case the problem solved with this command:
ssh $MachineIP " echo \"$CM_Config\" > \"$mName/CM_CONFIG\" "
实际上,如果没有用\括住我的变量,我的问题就没有解决.也许是因为这些变量的内容有点像bash命令并且在多行中.
In fact without \" enclosing my variable, my problem didn't solved. Maybe it is because that the content of these variables are somehow like bash command and are in multiple lines.