Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I pass y to [y/n] kind of questions in linux automatically

Tags:

linux

shell

I need to automate some installation, but in some commands it asks like "are you sure u want to continue[y\n]=?" How do I always pass y to all such type of questions to automate my script?

echo 'y y y' | sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

sudo yum install yum-plugin-replace

sudo yum replace mysql-libs --replace-with mysql55w-libs

sudo yum install mysql.`uname -i` yum-plugin-replace

echo yes "yes" | sudo yum install mysql55w mysql55w-server

sudo service mysqld start

sudo mysql_upgrade -u root

here is my shell script i need to execute it completely with out any such questions prompted.

like image 366
chinna2580 Avatar asked Oct 17 '14 18:10

chinna2580


People also ask

How do you pass Y or N in shell script?

This is best coupled with a case statement that can check to see if the user entered yes or no or something else. #!/bin/bash read -p "Do you want to proceed? (yes/no) " yn case $yn in yes ) echo ok, we will proceed;; no ) echo exiting...; exit;; * ) echo invalid response; exit 1;; esac echo doing stuff...

How do I pass two commands in Linux?

On Linux, there are three ways to run multiple commands in a terminal: The Semicolon (;) operator. The Logical OR (||) operator. The Logical AND (&&) operator.

How do I pass a yes command in bash?

A Sample Command That Asks a Yes/No Question. If we are doing this manually, we can just type y <Enter> and pass this prompt.


2 Answers

You can use the yes utility:

$ yes | sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
like image 175
Mureinik Avatar answered Sep 22 '22 15:09

Mureinik


Before resorting to the yes command (which risks giving y as an answer to things other than yes/no questions), read the documentation for the command you're using to see if it has an option to assume a "yes" answer to all (or most) interactive prompts.

I haven't used rpm much lately, but the --force option might be what you're looking for.

like image 39
Keith Thompson Avatar answered Sep 25 '22 15:09

Keith Thompson