bash read is being skipped when run from curl pipe

元气小坏坏 提交于 2019-12-14 03:45:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/16854041/bash-read-is-being-skipped-when-run-from-curl-pipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!