例如,虽然这有效:
$回声富 富
这不会:
$ /bin/sh -c echo foo
而这样做:
$ /bin/sh -c 'echo foo; 回声栏' 富 酒吧
有解释吗?
我有一个本地和一个远程主机,都运行 Ubuntu,外壳设置为 bash。在我的主目录中,我有两个文件file-1和file-2,分别位于本地主机和名为remote. 每个主目录中还有一些其他文件,我只想列出匹配file-*.
在本地,这些会产生预期的结果file-1 file-2:
$ ls file-*
$ bash -c 'ls file-*'
Run Code Online (Sandbox Code Playgroud)
但是这些命令会返回我的远程主目录中的所有文件。那里发生什么事了?
$ ssh remote bash -c 'ls file-*'
$ ssh remote bash -c 'ls "file-*"'
$ ssh remote bash -c 'ls file-\*'
$ ssh remote bash -c 'ls "file-\*"'
Run Code Online (Sandbox Code Playgroud)
我知道这只会ssh remote 'ls file-*'产生预期的结果,但为什么ssh remote bash -c 'ls ...'似乎放弃了传递给 的参数ls ...?(我还通过管道从远程执行的 ls 输出,它被传递了,所以ls似乎只有 ls受到影响:ssh remote bash -c 'ls …