在Linux Shell脚本中处理输入确认 [英] Handling input confirmations in Linux shell scripting

查看:824
本文介绍了在Linux Shell脚本中处理输入确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Linux Shell脚本来自动化我在Ubuntu 11.04上正在做的一些事情.

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

基本上,我正在编写一个Shell脚本来安装NGINX,MySQL和PHP,然后配置所有内容.我知道如何通过命令行执行所有操作.

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.

但是,我不知道如何处理流程要求用户输入的部分.例如,某些我使用apt-get安装的东西会要求您确认,即(Y)es或(N)o.

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.

我将如何精确地处理shell脚本中的自动确认,即在询问时自动确认是或否?

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

推荐答案

yes | ./script将为所有内容回答y.

否则,编写一个脚本,打印出所需的答案,例如:

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

 echo N
 echo Y
 echo Y

这篇关于在Linux Shell脚本中处理输入确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆