it-swarm.cn

无法通过管道传递到差异?

我想变得聪明一点,将远程文件与本地文件进行比较,而无需先手动下载它。我可以通过以下方式获取远程文件的内容

ssh [email protected] "cat path/file.name"

但是,将其传递给diff

ssh [email protected] "cat path/file.name" | diff path/file.name

给我这个:

diff: missing operand after `path/file.nae'
diff: Try `diff --help' for more information.

我已经设置了ssh密钥,因此它不会提示我输入密码。有什么解决方法?

81
user394

尝试使用-代表标准输入。

ssh [email protected] "cat path/file.name" | diff path/file.name -

99
Hemant

这是一种解决方法:diff似乎接受<(expr)作为论点:

diff <(ssh \"cat path/file.name/") <(cat path/file.name)
68
user394

用管道传递到差异相当于运行

diff path/file.name

然后,一旦运行,键入文件的全部内容。

如您所见,这不是您所期望的。

4
Macha
diff /tmp/localtempfile <(ssh -A -o StrictHostKeyChecking=no [email protected] "cat /tmp/remotetempfile")
1
Vlad