老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

shell腳本中case條件控制語句的使用-創新互聯

本篇內容介紹了“shell腳本中case條件控制語句的使用”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

成都創新互聯是一家專注于成都網站設計、成都做網站與策劃設計,大興網站建設哪家好?成都創新互聯做網站,專注于網站建設10年,網設計領域的專業建站公司;建站業務涵蓋:大興等地區。大興做網站價格咨詢:028-86922220

在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去做點事。

“shell腳本中case條件控制語句的使用”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!


網站欄目:shell腳本中case條件控制語句的使用-創新互聯
本文地址:http://www.xueling.net.cn/article/jhdso.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 国产精品欧美久久久久久日本一道 | 91亚洲国产成人精品一区二三 | 欧美一级黄色录相| 亚洲人成a在线网站 | 久久久999精品免费 国产欧美久久久久 | 91视频国产一区 | 牛和人交videos欧美3d | 97精品国产91久久久久久久 | 国产精品12区 | 日美韩一区二区三区 | 欧美人妖另类hd1080p | 欧美日韩一区二区三区久久精品 | 色黄大色黄女片免费中国 | 亚洲高清在线看 | 日韩精品中文字幕一区二区 | 精品人妻无码一区二区三区四区无码 | 国产亚洲精品AA片在线不卡 | 日本伦奷在线播放 | 日韩资源在线观看 | 欧美一级黄色免费 | 成人蜜桃| 91久久久一线二线三线品牌 | 日韩高清在线观看不卡一区二区 | 美女视频黄的免费的 | 亚洲av永久综合在线观看红杏 | 亚洲人影院 | 亚洲成人免费视频在线观看 | 国产精品中文字幕一区二区 | 国产欧美一区二区三区视频在线观看 | 女人19水真多免费毛片 | 超碰公开97| 久久久久99精品久久久久 | 久久免费看少妇高潮a片特黄网站 | 99热偷拍| 日本少妇被爽到高潮动态图 | 国产传媒免费 | 大伊香蕉精品一区视频在线 | 91免费黄色软件 | 亚洲黄色录像片 | 桃花视频大全不卡免费观看网站 | 免费精品国偷自产在线青年 |