[英]cat in multiple ssh commands does not work
This is probably very basic but unfortunately I have no idea how to google it. 这可能是非常基本的,但是不幸的是我不知道如何使用谷歌搜索。
Why doesn't the snippet below work as expected? 为什么以下代码段无法按预期工作? I mean, how can I make
cat
point to the remote file? 我的意思是,如何使
cat
指向远程文件?
#!/bin/bash
ssh user@remoteaddress << EOF
mkdir sandpit
cd sandpit
echo "foo" > foo.txt
echo `cat foo.txt` > foo2.txt
EOF
Use it as: 用作:
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
Without quotes around starting EOF
all words are subject to shell expansion and reverse quotes are expanded in your current shell not on ssh. 如果在
EOF
开头没有引号,则所有单词都将受Shell扩展的影响,反引号在当前Shell中而不是ssh上扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.