bash - 在多行上编写 SSH 命令

标签 bash shell ssh remote-access

我正在尝试远程登录到 shell 并在 shell 上执行一系列命令。 但为了使其更具可读性,我想将我的代码放在多行上。我应该怎么做?

ssh -o <Option> -x -l <user> <host> " $long_command1; $long_command2; ....  "

谢谢!

最佳答案

ssh 实际上只是将一个字符串传递给远程主机。这个字符串被提供给一个应该解释它的 shell(用户的登录 shell,通常类似于 bash)。因此,无论您想执行什么,都需要该远程登录 shell 可以解释,这是您必须遵守的全部规则。

您确实可以在命令字符串中使用换行符:

ssh alfe@sweethome "
  ls /home/alfe/whatever
  ping foreignhost
  date
  rm foobar
"

关于bash - 在多行上编写 SSH 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082646/

相关文章:

linux - 如何判断我是否在 screen 中?

mysql - 来自 MySQL Workbench 的 Raspberry Pi 3 连接

git - 当我 git clone : fatal: does not appear to be a git repository

linux - 如何使用 awk 按分隔符拆分文件并通过管道传输到另一个脚本中?

bash - Makefile - 如何区分变量赋值和命令

string - 如何使用 Bash 将多个空格替换为单个空格?

在 Linux 中创建简单的 Shell

ssh - 无法通过 ssh 推送到 GitLab 存储库

python - crontab 运行一个运行多个 python 脚本的 bash 脚本

node.js - I/O 绑定(bind)和 CPU 绑定(bind)