linux - 多个 ssh 命令中的 cat 不起作用

标签 linux bash shell ssh heredoc

这可能是非常基础的,但不幸的是我不知道如何用谷歌搜索它。

为什么下面的代码片段没有按预期工作?我的意思是,如何让 cat 指向远程文件?

#!/bin/bash

ssh user@remoteaddress << EOF
  mkdir sandpit
  cd sandpit
  echo "foo" > foo.txt
  echo `cat foo.txt` > foo2.txt
EOF

最佳答案

用作:

ssh -t -t user@remoteaddress<<'EOF'
mkdir sandpit
cd sandpit
echo "foo" > foo.txt
cat foo.txt > foo2.txt
xargs kill < pid.txt
exit
EOF

EOF 开头没有引号,所有单词都将在 shell 中展开,反引号在您当前的 shell 中展开,而不是在 ssh 上。

关于linux - 多个 ssh 命令中的 cat 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35684907/

相关文章:

java - 如何确定在 Linux 上使用 Java 还是 JRuby 是否正在运行不同的进程 ID?

linux - 使用哪种语言编写 Linux 发行版 GUI 安装程序

linux - Net::SSH::AuthenticationFailed:身份验证失败,用户无效

linux - 如何修复打开写入 P4 错误?

database - 备份 postgres 数据库时,系统提示我输入密码

Bash 拆分子串

linux - 我想删除linux中的所有文件和目录

linux - 运行远程脚本的意外行为

shell - UNIX 脚本 - 查找文件 - 显示日期

shell - shell脚本中的DEFINE是什么