好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > shell腳本中case條件控制語句的一個bug分析

shell腳本中case條件控制語句的一個bug分析

熱門標簽:打電話機器人接我是他的秘書 華鋒e路航港口地圖標注 江蘇云電銷機器人公司 如果做線上地圖標注 地圖標注員都是年輕人 百度地圖標注錯了有責任嗎 揭陽智能電話機器人推薦 河南信譽好的不封卡電話外呼系統 客服外呼系統怎么樣

在shell腳本中,發現case語句的一個問題。
就是指定小寫字母[a-z]和大寫字母[A-Z]的這種方法不管用了。

出現如下情況:

復制代碼 代碼如下:

[root@station1 ~]# cat case.sh
#!/bin/bash
while :
do
echo -n "input a letter: "
read var
case "$var" in
  [a-z]) echo "Lowercase letter";;
  [A-Z]) echo "Uppercase letter";;
 [0-9]) echo "Digit";;
  *) echo "Punctuation, whitespace, or other";;
esac
done
[root@station1 ~]# bash case.sh
input a letter: a
Lowercase letter
input a letter: A
Lowercase letter
input a letter: 2
Digit
input a letter: 0
Digit
input a letter: B
Lowercase letter
input a letter: y
Lowercase letter
input a letter: ^C
[root@station1 ~]#

可以看到當輸入大小寫字母都會輸出“Lowercase letter”

就當我疑惑不解的時候,奇跡發生了。。。。

復制代碼 代碼如下:

[root@station1 ~]# bash case.sh
input a letter: Z
Uppercase letter
input a 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.

再看下面這段代碼:

復制代碼 代碼如下:

[root@station1 ~]# cat case.sh
#!/bin/bash
while :
do
echo -n "input a letter: "
read var
case "$var" in
[a-c]) echo "Lowercase letter";;
[A-Z]) echo "Uppercase letter";;
[0-9]) echo "Digit";;
*) echo "Punctuation, whitespace, or other";;
esac
done
[root@station1 ~]# bash case.sh
input a letter: a
Lowercase letter
input a letter: b
Lowercase letter
input a letter: c
Lowercase letter
input a letter: d
Uppercase letter
input a letter: e
Uppercase letter
input a letter: ^C
[root@station1 ~]#

可以看出來它的編碼方式是:aAbBcCdDeE...yYzZ
所以才會出現這種情況。這也算是一個小bug吧,如果想真的想達到我們想要的結果,可以用posix的[:upper:]。
個人想法:有時候出現這種情況也不是個壞事,或許還可以利用這個bug去做點事。

您可能感興趣的文章:
  • 詳解JavaScript中循環控制語句的用法
  • 詳解JavaScript的流程控制語句
  • linux shell流程控制語句實例講解(if、for、while、case語句實例)
  • Flash中常用到的ActionScript控制語句用法
  • JavaScript中的for循環與雙重for循環詳解
  • C語言控制語句之 循環

標簽:許昌 邵陽 赤峰 婁底 巴彥淖爾 馬鞍山 金昌 淘寶邀評

巨人網絡通訊聲明:本文標題《shell腳本中case條件控制語句的一個bug分析》,本文關鍵詞  shell,腳本,中,case,條件,控制,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《shell腳本中case條件控制語句的一個bug分析》相關的同類信息!
  • 本頁收集關于shell腳本中case條件控制語句的一個bug分析的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 久久久精品欧美AV无码看动漫| 高h文激情后宫| 公交车上多人三级AV| 在电梯里她夹得我好爽| 94神马影院| 日韩精品在线免费观看| 无码性教育片在线播放的注意事项| 潘金莲西门庆一级淫片aaaaaa| 91一级毛片| 《试看120秒做受小视频》| 寡妇**毛片免费播放| gayspanking男男打屁股m| 国产一级毛片无码AAAAAA看| 锵锵锵锵锵水好多免费观看| 久久国产精品自线拍免费| 做做网站| 一级一级一级毛片免费毛片| 99久久精品国产99久久久久久禁果 | 高清一级毛片免免费看| 女同肉瓣摩擦gl视频免费观看| 女人被躁到高潮免费视频网站95| 黑人寄宿侵犯女主人在线播放| 97就要鲁就要鲁夜夜爽| 蒲肉团在线观看完整视频| 男生被爽到呻吟的音频| 久久人人爽爽爽人久久久爱密桃 | 狠狠躁日日躁夜夜躁厨房掀起| 91一区二区国产好的精华液怎么用| 丝袜好紧…老师我要进去了| 十分钟视频免费观看在线播放www| 张筱雨人体337p人体| 欧美a级黄色| 色戒原片| 全黄h全肉短篇禁乱公交车| 91情侣视频| 野花视频免费直播在线观看| 免费黄色一级视频| 久爱成疾在线观看视频在线播放视频| 一阴夹两阳后续走势| 绿帽娇妻肚子被灌满精怀孕| 3D动漫超肉无修网站在线观看|