【发布时间】:2012-07-18 19:19:46
【问题描述】:
我需要在远程机器上执行多个命令,并使用 ssh 来执行此操作,
ssh root@remote_server 'cd /root/dir; ./run.sh'
在脚本中,我想在执行run.sh时传递一个局部变量$argument,比如
ssh root@remote_server 'cd /root/dir; ./run.sh $argument'
它不起作用,因为在单引号中 $argument 没有按预期方式解释。
编辑:我知道可以使用双引号,但这有什么副作用吗?
【问题讨论】:
-
唯一的副作用是在引用的字符串中插入变量。如果您在该字符串中有其他与变量无关的
$,则需要转义那些不是变量的。 -
这对我有用
argument=10;ssh root@x.x.x.x 'head -'$argument' some.php'; -
@MarcB 如果你把它作为一个答案,我会接受它