Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash read is being skipped when run from curl pipe

I'm building a bootstrap for a github project and would like it to be a simple one-liner. The script requires a password input.

This works and stops the script to wait for an input:

curl -s https://raw.github.com/willfarrell/.vhosts/master/setup.sh -o setup.sh
bash setup.sh

This does not, and just skips over the input request:

curl -s https://raw.github.com/willfarrell/.vhosts/master/setup.sh | bash

setup.sh contains code is something like:

# code before
read -p "Password:" -s password
# code after

Is it possible to have a clean one-liner? If so, how might one do it?

Workaround:

Use three commands instead of piping output.

curl -s https://raw.github.com/willfarrell/.vhosts/master/setup.sh -o vhosts.sh && bash vhosts.sh && rm vhosts.sh

like image 936
will Farrell Avatar asked May 31 '13 09:05

will Farrell


2 Answers

I had the same exact problem as the OP and was looking for an answer. This question was one of the first hits on Google for me and since it doesn't have a real answer yet, here's the command that I eventually stumbled upon which solved my need of using read in a remote script.

bash <(curl -s https://example.com/my-bash-script.sh)
like image 178
Tundra Fizz Avatar answered Sep 18 '22 01:09

Tundra Fizz


With the pipe, the read reads from standard input (the pipe), but the shell already read all the standard input so there isn't anything for the read to read.

like image 43
Jonathan Leffler Avatar answered Sep 18 '22 01:09

Jonathan Leffler