Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling input confirmations in Linux shell scripting

I'm writing a Linux Shell Script to automate a few things I'm doing on Ubuntu 11.04.

Basically, I'm writing a shell script to install NGINX, MySQL, and PHP, and then configure everything. I know how to do everything via the command-line.

However, I don't know how I'm going to handle the parts where the process asks for user input. For example, certain things I install with apt-get ask you for a confirmation i.e. (Y)es or (N)o.

How exactly would I handle auto-confirmation in the shell script i.e. to automatically confirm Yes or No when asked?

like image 478
ObiHill Avatar asked Sep 14 '11 02:09

ObiHill


People also ask

What is $1 $2 in shell script?

Shell scripts have access to some "magic" variables from the environment: $0 - The name of the script. $1 - The first argument sent to the script. $2 - The second argument sent to the script.


1 Answers

yes | ./script will answer y for everything.

Otherwise, write a script that prints the answers you want, eg:

 echo N
 echo Y
 echo Y
like image 104
wormsparty Avatar answered Oct 03 '22 02:10

wormsparty