这可能是非常基础的,但不幸的是我不知道如何用谷歌搜索它。
为什么下面的代码片段没有按预期工作?我的意思是,如何让 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/