最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

ssh节点上的Eash bash变量

IT培训 admin 13浏览 0评论

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)"`])

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. 暂无评论