0

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?

#!/bin/bash

ssh user@remoteaddress << EOF
  mkdir sandpit
  cd sandpit
  echo "foo" > foo.txt
  echo `cat foo.txt` > foo2.txt
EOF
Cyrus
  • 84,225
  • 14
  • 89
  • 153
akai
  • 2,498
  • 4
  • 24
  • 46

1 Answers1

3

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks, this works. Well, what I actually want to do is `kill \`cat pid.txt\``. How should I do in this case? – akai Feb 28 '16 at 16:17
  • 1
    Now I've checked the edit and everything's solved. thank you very much. – akai Feb 28 '16 at 16:21