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

查看:85
本文介绍了在 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 的所有内容.

yes | ./script will answer y for everything.

否则,编写一个脚本来打印您想要的答案,例如:

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

 echo N
 echo Y
 echo Y

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

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