相关疑难解决方法(0)

为什么称为 /bin/sh -c echo foo 的 echo 不输出任何内容?

例如,虽然这有效:

$回声富
富

这不会:

$ /bin/sh -c echo foo

而这样做:

$ /bin/sh -c 'echo foo; 回声栏'
富
酒吧

有解释吗?

command-line shell echo arguments

16
推荐指数
3
解决办法
8625
查看次数

为什么 ls 参数在通过 ssh 主机 bash -c 运行的命令中似乎不起作用?

我有一个本地和一个远程主机,都运行 Ubuntu,外壳设置为 bash。在我的主目录中,我有两个文件file-1file-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 …

bash ssh wildcards

10
推荐指数
1
解决办法
994
查看次数

标签 统计

arguments ×1

bash ×1

command-line ×1

echo ×1

shell ×1

ssh ×1

wildcards ×1