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

Chinaunix

標(biāo)題: 請教怎樣判斷輸入的是否為整數(shù) [打印本頁]

作者: 123freebird    時間: 2012-01-09 13:46
標(biāo)題: 請教怎樣判斷輸入的是否為整數(shù)
本帖最后由 123freebird 于 2012-01-09 13:54 編輯

read -p "enter your number" test

怎么判斷輸入的test是整數(shù)
使用expr $test+1 運(yùn)算 ,判斷$?的值?
這種方法 當(dāng)輸入的為-1的時候 $test+1的值為0,表達(dá)式的值就是false $?為1
或者用正則表達(dá)式 怎么用的 請教
作者: yinyuemi    時間: 2012-01-09 14:27
回復(fù) 1# 123freebird
  1. [[ -z ${test//[0-9]} ]] && echo "Integar" || echo "Non-integer"
復(fù)制代碼

作者: zooyo    時間: 2012-01-09 14:36
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽
作者: jason680    時間: 2012-01-09 15:21
回復(fù) 2# yinyuemi

$ echo ">>>$test<<<"
>>><<<

$ [[ -z ${test//[0-9]} ]] && echo "Integar" || echo "Non-integer"
Integar

$ [[ -n $test && -z ${test//[0-9]} ]] && echo "Integar" || echo "Non-integer"
Non-integer

   
作者: 123freebird    時間: 2012-01-09 15:26
${test//[0-9]}   這個沒看懂
作者: fllintel    時間: 2012-01-09 15:49

${test//[0-9]}    求解釋..............
作者: jason680    時間: 2012-01-09 15:55
本帖最后由 jason680 于 2012-01-09 15:55 編輯

置頂文: shell 十三問?
8) $(( )) 與 $( ) 還有${ } 差在哪?
作者: 123freebird    時間: 2012-01-09 16:47
回復(fù) 7# jason680


    把數(shù)字替換為空    ${test//[0-9]}
    是這樣理解么  但是如果是把數(shù)字替換為空 那數(shù)字應(yīng)該在前面啊
    但是我試了一下 為什么也可以呢
作者: jason680    時間: 2012-01-09 16:51
回復(fù) 8# 123freebird

what do you want to say!!??
   
作者: 123freebird    時間: 2012-01-09 17:00
回復(fù) 9# jason680


    ${test//[0-9]} 的作用是不是把test中的數(shù)字替換為空? 如果是的話 ,那按照13問上寫的,是不是${test/[0-9]*/}這樣寫啊?背替換的在前
作者: Shell_HAT    時間: 2012-01-09 17:03
回復(fù) 10# 123freebird


/是替換第一個匹配,//是替換所有的匹配
作者: jason680    時間: 2012-01-09 17:05
回復(fù) 10# 123freebird

did you see the red word and understand them with different between one and two slash (/ and //).

我們也可以對變量值裡的字串作替換:
${file/dir/path}:將第一個 dir 提換為 path:/path1/dir2/dir3/my.file.txt
${file//dir/path}:將全部 dir 提換為 path:/path1/path2/path3/my.file.txt   
作者: howge    時間: 2012-01-12 11:08
回復(fù) 2# yinyuemi

學(xué)習(xí)~~


   
作者: waker    時間: 2012-01-12 11:16
鉆下牛角尖兒
1.3e5是不是整數(shù)
-3是不是整數(shù)
作者: winway1988    時間: 2012-01-12 11:52
  1. ${string/substring/replacement}
  2. Replace first match of $substring with $replacement.
  3. ${string//substring/replacement}
  4. Replace all matches of $substring with $replacement.
復(fù)制代碼
  1. What happens if no $replacement string is supplied?
  2. A simple deletion takes place.
復(fù)制代碼





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