Auto confirm EULA in bash script
I am writing a bash script that is supposed to do some confirmation and also install software. F开发者_运维知识库irst step of the installation process is that I am being asked to confirm the EULA and type 'yes'. Is there a way to get the 'yes' in there from the bash script?
The command yes
outputs a never-ending stream of a specified string, or y
if unspecified.
$ yes | head y y y y y y y y y y $ yes yes | ./interactive-installer # something like this?
sometimes you can use
echo "yes"|./interactive-installer
Expect may be of help there. I've never used it myself, but I understand that it allows you to specify pre-programmed responses to specific prompts.
Use read
.
#!/bin/sh
echo -n "Confirm? (y/n):"
read confirm_val
if [[ "$confirm_val" == "y" ]] ; then
echo "Confirmed!"
else
echo "Not confirmed!"
fi
#!/bin/sh
echo -n "Confirm me ? (yes/no):"
read choice
if [ "$choice" == "yes" ] ; then
echo "Confirmed!"
else
echo "Not confirmed!"
fi
精彩评论