多个 ssh 命令中的 cat 不起作用
cat in multiple ssh commands does not work
这可能是非常基础的,但不幸的是我不知道如何google它。
为什么下面的代码片段没有按预期工作?我的意思是,如何让 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 中扩展。
这可能是非常基础的,但不幸的是我不知道如何google它。
为什么下面的代码片段没有按预期工作?我的意思是,如何让 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 中扩展。