亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: shell的case分支語句無法處理正則表達式嗎? [打印本頁]

作者: samsun639    時間: 2013-06-27 12:58
標題: shell的case分支語句無法處理正則表達式嗎?
例子:test.sh 如下
case  $1 in
  “hello")
             echo "hello"
             ;;
   "[1-9]*")
             echo "number"
             ;;
esac

執(zhí)行:
./test.sh 12  --無任何顯示
執(zhí)行:
./test.sh hello --顯示“hello”

請教: 查了下case應(yīng)該是支持正則表達式的,但是實測結(jié)果卻是不可以,不知問題出在哪里?


作者: 關(guān)陰月飛    時間: 2013-06-27 13:15
回復 1# samsun639


    把 "[0-9]*" 的引號去掉改成  [0-9]*
作者: samsun639    時間: 2013-06-27 13:23
回復 2# 關(guān)陰月飛

thanks, 剛剛發(fā)完帖子自己試了下也試出來了。  這個問題還是蠻奇葩的。


   
作者: zhaopingzi    時間: 2013-06-27 13:23
本帖最后由 zhaopingzi 于 2013-06-27 13:24 編輯



  1. case  $1 in
  2.   “hello")
  3.              echo "hello"
  4.              ;;
  5.    [0-9]*)
  6.              echo "number"
  7.              ;;
  8. esac
復制代碼

作者: samsun639    時間: 2013-06-27 13:26
回復 4# zhaopingzi


   thanks, 但是不知道為啥會這樣,有點奇葩
作者: zhaopingzi    時間: 2013-06-27 13:28
""住就變成字符串了
作者: samsun639    時間: 2013-06-27 13:33
回復 6# zhaopingzi


    明白了?磥怼啊 和 '' 之前還是沒有弄明白異同點。。 thanks
作者: seesea2517    時間: 2013-06-27 15:10
是正則么?看幫助不是這么說的:
       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 substitution, command  substitution,  pro-
              cess substitution and quote removal.  Each pattern examined is expanded using tilde expansion, parameter
              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.  After the first match, no  sub-
              sequent  matches  are  attempted.   The exit status is zero if no pattern matches.  Otherwise, it is the
              exit status of the last command executed in list.

作者: zooyo    時間: 2013-06-27 16:37
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽
作者: mmwobuaini    時間: 2013-06-27 16:55
  1. [root@localhost tmp]# sh test.sh "[1-9]*"
  2. number
復制代碼
number出來了
作者: Shell_HAT    時間: 2013-06-27 18:38
回復 5# samsun639


    你得按照shell能理解的語法寫代碼,而不是按照自己想出來的語法寫代碼。




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2