tags:

views:

153

answers:

5

I am writing a bash script that is supposed to do some confirmation and also install software. First 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?

A: 

Use read.

#!/bin/sh

echo -n "Confirm? (y/n):"
read confirm_val

if [[ "$confirm_val" == "y" ]] ; then
  echo "Confirmed!"
else
  echo "Not confirmed!"
fi
Trent Davies
Well this script prompts the user to confirm, What I need is the opposite. The software I am trying to install from my script asks me to confirm their EULA. Now my problem is how to confirm their EULA from my script.
ajmurmann
A: 
#!/bin/sh

echo -n "Confirm me ? (yes/no):"
read choice

if [ "$choice" ==  "yes" ] ; then
        echo "Confirmed!"
else
        echo "Not confirmed!"
fi
muruga
+2  A: 

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?
ephemient
That's exactly what I was looking for. Thank you very, very much!
ajmurmann
+1  A: 

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.

Chris Jester-Young
Thank you very much. I am sure this will be helpful in the future!
ajmurmann
+1  A: 

sometimes you can use

echo "yes"|./interactive-installer

ghostdog74
Thanks! Just tried it and it works as well.
ajmurmann