if判斷的幾種用法

2021-09-20 17:27:22 字數 1732 閱讀 7111

if判斷語句1:

1

2

3

4

5

6

7

8

9

#!/bin/bash

read-p"please input a number: "n

m=`echo$n|sed's/[0-9]//g'`

if[ -z $m ]

then

echo$n

else

echo"please input valid number."

fi

if判斷語句2:

1 #!/bin/bash

2 read -p "please input a number: " n

3 m=`echo $n|sed 's/[0-9]//g'`

4 if [ -n "$m" ]

5 then

6      echo "please input valid number."

7 else

8   echo $n

9 fi

注意方括號邊上有空格。

[ -z $m ] 判斷m是否不為空,如果為空,則該條件不成立

[ -n "$m" ] 注意要有雙引號,否則不管用,如果為空,條件成立;-n 就是 not null ,不為空。

read 命令用於和使用者互動,它把使用者輸入的自護傳作為變數值

-lt (小於) -gt大於 -le小於或等於  -ge大於或等於  -eq等於  -ne不等於

表示判斷用法:

1、== 後面跟字母或數字

2、一般用0或1表示判斷條件是否成立

2、cat /etc/passwd > /dev/null 2>&1

> 表示正確輸出

2> 表示錯誤輸出

&1 表示前面 > 後面的檔案。

比如: cat /etc/passwd > /dev/null 2>&1

這樣會把正確和錯誤的日誌全部輸入到/dev/null

3、if [ $a -gt 10-o $a -lt 5 ]

-o是or: 表示或者  等於||

4、if [ $a -gt 100-a $a -lt 1000 ]; then ...; fi

-a是and:表示而且得意思    等於&&

5、grep -q不輸出匹配結果

if grep -q '^snake1:' /etc/passwd

;then echo "snake exist.";fi

#標示紅色作為條件判斷,寫成一條語句要用分號;作為分隔符

Intent的幾種用法

returnit new intent intent.action delete,uninstalluri install apk uri installuri uri.fromparts package null returnit new intent intent.action package ...

php curl的幾種用法

1.php curl的預設呼叫方法,get方式訪問url curl setopt ch,curlopt httpheader,header 設定http頭 curl setopt ch,curlopt url,url curl setopt ch,curlopt useragent,user age...

Intent的幾種用法

intent 應該算是android中特有的東西。你可以在intent中指定程式 要執行的動作 比如 view,edit,dial 以及程式執行到該動作時所需要的資料。都指定好後,只要呼叫startactivity android系統會自動尋找最符合你指定要求的應用 程式,並執行該程式。下面列出幾種...