相关疑难解决方法(0)

如何在不知道远程用户的登录 shell 的情况下通过 ssh 执行任意简单的命令?

ssh 运行时有一个烦人的功能:

ssh user@host cmd and "here's" "one arg"
Run Code Online (Sandbox Code Playgroud)

它不是cmd用它的参数运行它host,而是将它cmd和带有空格的参数连接起来,并运行一个 shellhost来解释结果字符串(我想这就是为什么它被调用ssh而不是sexec)。

更糟糕的是,您不知道将使用什么 shell 来解释该字符串,因为它的登录 shelluser甚至不能保证像 Bourne 一样,因为仍然有人使用tcsh作为他们的登录 shell 并且fish还在增加。

有没有办法解决这个问题?

假设我有一个命令作为存储一个在参数列表bash阵列,其每一个可以包含的非空字节的任何序列,是否有任何方式把它上执行hostuser以一致的方式,无论该登录壳的userhost(我们假设它是主要的 Unix shell 系列之一:Bourne、csh、rc/es、fish)?

我应该能够做出的另一个合理假设是,有一个sh与Bourne 兼容的命令host可用$PATH

例子:

cmd=(
  'printf'
  '<%s>\n'
  'arg with $and spaces'
  '' # empty
  $'even\n* * *\nnewlines'
  "and 'single quotes'"
  '!!'
)
Run Code Online (Sandbox Code Playgroud)

我可以在本地运行它与 …

ssh quoting portability

28
推荐指数
1
解决办法
4133
查看次数

标签 统计

portability ×1

quoting ×1

ssh ×1