Bash中不区分大小写的比较 [英] Case insensitive comparison in Bash

查看:138
本文介绍了Bash中不区分大小写的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在不区分大小写的while语句中编写比较.基本上,我只是想简化以下内容,以便对用户显示是或否的问题提示...

I'm trying to write a comparison in a while statement that's case insensitive. Basically, I'm simply trying to shorten the following to act on a yes or no question prompt to the user ...

while[ $yn == "y" | $yn == "Y" | $yn == "Yes" | $yn == "yes" ] ; do

解决这个问题的最佳方法是什么?

What would be the best way to go about this?

推荐答案

shopt -s nocasematch
while [[ $yn == y || $yn == "yes" ]] ; do

或:

shopt -s nocasematch
while [[ $yn =~ (y|yes) ]] ; do

注意

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