最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ssh节点上的Eash bash变量

网站源码admin16浏览0评论

ssh节点上的Eash bash变量

ssh节点上的Eash bash变量

[在节点中执行bash命令并传递动态参数时,标准方法是使用spawn并避免转义。那是:

const filename = 'file with spaces'
spawn('ls', [filename]) // All good, received 'file with spaces'

这很简单,因为文件名是作为独立变量传递给bash的。

现在,如果我想通过ssh进行同样的操作会怎样?以下是not选项:

const filename = 'file with spaces'
spawn('ssh', [host, 'ls', filename]) // Wrong!! Received 'file' 'with' 'spaces'

Ssh接受ls和文件名作为vargars。加入并执行,这将达到目的。

回答如下:

一种方法是使用具有预期字符的base64传递值,然后在bash中转义

spawn('ssh', [host, 'ls', `"$(echo ${btoa(filename)} | base64 -d)"`])

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论