Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I do something like this with one ssh command:

echo << EOF
echo "Choose a file:" *
read f
rm -r "$f"
EOF | ssh user@host

I can use the -tt (yes two t's) with ssh to make ssh read from stdin, however it doesn't seem to allow read to work.

Is there a way of doing this?

share|improve this question
I don't get what your "like this"-command should be an example for.. – Karma Fusebox Feb 18 '13 at 0:12
@KarmaFusebox I added a better example. – Tyilo Feb 18 '13 at 0:46
up vote 2 down vote accepted

If I understand your example command correctly, this should work:

ssh user@host 'echo "Input something:"; read VAR; echo "Got: $VAR"'              

That worked when "host" was a Slackware Linux server, and ssh ran on an Arch linux laptop. My shell on the Slackware server is zsh 4.2.6 (i486-slackware-linux-gnu). Since read is a shell built-in, I imagine that choice of shell could have something to do with it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.