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.

  • Duplicate stackoverflow.com/questions/15026580/… – 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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