Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

Hi all I am new to shell scripting and please help me in this situation.
I have created a shell script named ./remote1 which looks like below.

# ./remote1 file
ssh username@x.x.x.x 'bash -s' < ./createdir

Here 'createdir' is another file i had created which is given below

# ./createdir file
echo "give directory name"
read name
mkdir ~/$name

If I run the ./createdir alone in my machine, it will execute without any problem.
If I execute ./remote1, it will not wait for input the data for the 'read' command.Please anyone could help me to solve this problem.
Thanks in advance.

share|improve this question
Duplicate… – Gilles Quenot Feb 22 '13 at 15:05
is createdir file present in the remote computer(x.x.x.x)? – Gaurav Sharma Feb 22 '13 at 15:13
This works: ssh host "bash -c 'read data; echo \$data'" - I suspect using bash -s does something like block any builtins (eg, read) from using STDIN, but I am not certain. – chronitis Feb 22 '13 at 15:15

Looks like you want to exec the command via ssh on another machine. Bute there is no one who could give an answer to the read command.

Try to read the name on the local machine and put in a variable like:


echo "give directory name"
read name
ssh username@x.x.x.x mkdir ~/$name

I cant test it now, but I think this will execute the mkdir on the remote machine directly vis ssh, without anoter script on 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.