变量没有传递到远程机器

Variable is not passed to the remote machine

我正在尝试使用 ssh 从本地计算机执行到远程计算机。我已经设置了 $HN$ManagedServerName 值 - 但是当我执行以下命令时 - $ManagedServerName 变量取空值

ssh $HN 'echo `cd /u01/app/oracle/product/webcenter/sites; find -name "*.ini" -not -path "./Shared/*" -not -path ".logs/*" -exec sed -i 's/TWP/'$ManagedServerName'/g' {} \;

求推荐,

谢谢

我想您会希望在 sed 命令中使用双引号,这样您就可以对搜索词进行适当的变量扩展和连接:

ssh $HN 'echo `cd /u01/app/oracle/product/webcenter/sites; find -name "*.ini" -not -path "./Shared/*" -not -path ".logs/*" -exec sed -i "s/TWP/$ManagedServerName/g" {} \;

你的引用有误。 echo 之前的单引号被 sed 表达式中的第一个单引号关闭,然后您在 $ManagedServerName 周围打开一个新的单引号,因此另一侧的 shell 试图扩展该变量。尝试:

sed -i "s/TWP/'"$ManagedServerName"'/g"