位置: 编程技术 - 正文
在shell脚本中,发现case语句的一个问题。就是指定小写字母[a-z]和大写字母[A-Z]的这种方法不管用了。
出现如下情况:
可以看到当输入大小写字母都会输出“Lowercase letter”
就当我疑惑不解的时候,奇迹发生了。。。。
当输入大写Z的时候,终于出现了我们想要的结果:Uppercase letter后来在man bash文档中也没有关于"-"代表范围的说明,值说想匹配"-",就把"-"放到[]中最前面或者最后面。case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esacA case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for pathnameexpansion (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 isenabled, the match is performed without regard to the case of alphabetic characters. When a match is found, the corresponding list isexecuted. If the ;; operator is used, no subsequent matches are attempted after the first pattern match. Using ;& in place of ;; causesexecution to continue with the list associated with the next set of patterns. Using ;;& in place of ;; causes the shell to test the nextpattern list in the statement, if any, and execute any associated list on a successful match. The exit status is zero if no patternmatches. Otherwise, it is the exit status of the last command executed in list.
再看下面这段代码:
可以看出来它的编码方式是:aAbBcCdDeE...yYzZ所以才会出现这种情况。这也算是一个小bug吧,如果想真的想达到我们想要的结果,可以用posix的[:upper:]。个人想法:有时候出现这种情况也不是个坏事,或许还可以利用这个bug去做点事。
推荐整理分享shell脚本中case条件控制语句的一个bug分析(linux脚本case),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:shell case命令,shell case命令,shell脚本 case,shellcase语句,shellcase语句,shell脚本 case,shell脚本的case语句,shell脚本 case,内容如对您有帮助,希望把文章链接给更多的朋友!
shell编程基础之认识与学习BASH 1、认识Bash通过Shell将输入的指令与Kernel沟通,让Kernel控制硬件工作查看Shell:cat/etc/shell登录后预设的shell类型记录在/etc/passwd中,与账户相关命令别名:al
linux基础之Shell Script入门介绍 linux基础之ShellScript1ShellScipt使用指令和基本程序设计结构写成的程序,可以完成复杂的处理流程1.1程序书写#!/bin/bash#Program:#Thisprogramshows"HelloWrold"inyourscre
更改linux用户登录shell的操作方法 1、查看机器安装了哪些shell?有两种方法可以查看。第一种:[rocrocket@wupengchong~]$chsh-l/bin/sh/bin/bash/sbin/nologin/bin/zsh第二种:[rocrocket@wupengchong~]$cat/etc/shells
标签: linux脚本case
本文链接地址:https://www.jiuchutong.com/biancheng/376766.html 转载请保留说明!上一篇:一个shell for循环与case结合的脚本(监控程序状态)(shell for循环执行命令)
下一篇:shell编程基础之认识与学习BASH(shell编程总结)
友情链接: 武汉网站建设