I'm trying to create a bash script that can be easily downloaded and run from terminal. Inside the bash script there are a couple of user inputs.
Running:
sudo wget -O - https://script.com/script.sh | bash
This will download the script and run it with bash but will ignore the user input in script.sh:
echo "Please enter a username:"
read -p 'Username: ' uservar
echo "Please enter a strong password:"
read -sp 'Password: ' passvar
echo
echo "
user=$uservar
password=$passvar
" >> ~/.data/cred.conf
echo "Succesfully installed."
Running:
sudo wget -O - https://script.com/script.sh && bash ./script.sh
Works fine and prompts for user input. Is there any way to make user input work with a pipe ( | bash
) ?
from comment
| bash <(cat) </dev/tty
why and how it works
<(cat)
construct allows
</dev/tty
redirects pseudo terminal device /dev/tty
to input of bash process
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.