Reputation: 53
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)
Upvotes: 3
Views: 1403
Reputation: 53
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
"
Upvotes: 0
Reputation: 14137
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)
Upvotes: 1
Reputation: 1075
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
Upvotes: 0