• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > shell脚本中case条件控制语句的一个bug分析

shell脚本中case条件控制语句的一个bug分析

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了shell脚本case,shell脚本中的case,shell脚本if语句,shell脚本执行sql语句,shell脚本循环语句等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在shell脚本中,发现case语句的一个问题。
就是指定小写字母[a-z]和大写字母[A-Z]的这种方法不管用了。

出现如下情况:

可以看到当输入大小写字母都会输出“Lowercase letter”

就当我疑惑不解的时候,奇迹发生了。。。。

当输入大写Z的时候,终于出现了我们想要的结果:Uppercase letter
后来在man bash文档中也没有关于"-"代表范围的说明,值说想匹配"-",就把"-"放到[]中最前面或者最后面。
case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
A case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for pathname
expansion (see Pathname Expansion below). The word is expanded using tilde expansion, parameter and variable expansion, arithmetic sub-
stitution, command substitution, process substitution and quote removal. Each pattern examined is expanded using tilde expansion, param-
eter and variable expansion, arithmetic substitution, command substitution, and process substitution. If the shell option nocasematch is
enabled, the match is performed without regard to the case of alphabetic characters. When a match is found, the corresponding list is
executed. If the ;; operator is used, no subsequent matches are attempted after the first pattern match. Using ;& in place of ;; causes
execution to continue with the list associated with the next set of patterns. Using ;;& in place of ;; causes the shell to test the next
pattern list in the statement, if any, and execute any associated list on a successful match. The exit status is zero if no pattern
matches. Otherwise, it is the exit status of the last command executed in list.

再看下面这段代码:

可以看出来它的编码方式是:aAbBcCdDeE...yYzZ
所以才会出现这种情况。这也算是一个小bug吧,如果想真的想达到我们想要的结果,可以用posix的[:upper:]。
个人想法:有时候出现这种情况也不是个坏事,或许还可以利用这个bug去做点事。

</div>

您可能想查找下面的文章:

  • Shell脚本case语句简明教程
  • shell脚本中case条件控制语句的一个bug分析
  • 一个shell for循环与case结合的脚本(监控程序状态)

相关文章

  • linux sed命令详解(推荐)
  • expect实现单台、多台服务器批量scp传输文件
  • Shell脚本中实现把输入的密码转换为*(星号)的方法
  • linux shell 脚本实现tcp/upd协议通讯(重定向应用)
  • Linux上安装和卸载rpm软件包的方法
  • Linux 怎么实现添加FTP用户并设置权限的方法
  • 大小写字母转换的shell脚本代码
  • Linux命令每天必学(55)之traceroute命令
  • 检测网站down掉后自动发信的shell脚本代码
  • 监控服务器swap并重启php的Shell脚本

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Shell脚本实现监控rsync数据是否传输完
    • linux仿写chmod命令
    • linux shell命令行选项与参数用法详解
    • Bash中数组的操作教程
    • linux shell 管道命令(pipe)使用及与shell重定向区别
    • linux shell数组深入学习理解
    • Shell脚本实现自动修改IP、主机名等功能分享
    • 使用shell脚本分析网站日志统计PV、404、500等数据
    • linux下怎么解压.tar.gz .tar.bz2命令
    • Linux下查找后门程序 CentOS 查后门程序的shell脚本

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有