3

I'm new to Bash scripting, so please be gentle.

I'm connected to a Ubuntu server via SSH (PuTTY) and when I run this command, I expect the bash script that downloads and executes to allow user input and then echo that input. It seems to just write out the echo label for the input request and terminate.

wget -O - https://raw.github.com/aaronhancock/pub/master/bash/readtest.sh | bash

Any clue what I might be doing wrong?

UPDATE: This bash command does exactly what I wanted

bash <(wget -q -O - https://raw.github.com/aaronhancock/pub/master/bash/readtest.sh)
2
  • There is no need to update the question with the contents of the answer. The accepted answer is visible below anyway. Commented Nov 30, 2012 at 17:26
  • My update was slightly different than the accepted answer below, so I thought I would share. Commented Nov 30, 2012 at 18:00

3 Answers 3

1

Jonathan already mentioned: bash takes its stdin from the pipe. And therefore you cannot pipe the script into bash when you want to interactively input something. But you could use the process substitution feature of bash (assumed your login shell is a bash):

bash <(wget -O - https://raw.github.com/aaronhancock/pub/master/bash/readtest.sh)
Sign up to request clarification or add additional context in comments.

1 Comment

Or just wget to a file and then execute. No need for rocket science, I would say.
0

Bash is taking stdin from the pipe, not from the terminal. So you can't pipe a script to bash and still use the "read" command for user input.

Notice that you have the same problem if you save the script to a local file and pipe it to bash:

less readtest.sh | bash

1 Comment

Jonathan, is there a way to get user input from the bash script through SSH then?
0

I found this also works and helps keep the data in the current scope.

eval "wget -q -O - https://raw.github.com/aaronhancock/pub/master/bash/readtest.sh"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.