數字比較

[ "$a" -eq "$b" ] 數字相等
[ "$a" -ne "$b" ] 數字不相等
[ "$a" -gt "$b" ] $a > $b
[ "$a" -ge "$b" ] $a >= $b
[ "$a" -lt "$b" ] $a < $b
[ "$a" -le "$b" ] $a <= $b

字串比較

[ "$a" = "$b" ] $a = $b
[ "$a" != "$b" ] $a 不等於 $b
[ -z "$a" ] $a是否為空字串
[ -n "$b" ] $b是否不為空字串

檔案情形

[ -r /temp/file ] 是否可讀
[ -w /temp/file ] 是否可寫
[ -x /temp/file ] 是否可執行
[ -f /temp/file ] 是否為檔案
[ -d /temp/file ] 是否為目錄
[ -s /temp/file ] 是否大於0
[ -p /temp/file ] 是否為pipe
[ -L /temp/file ] 是否為link

 

a && b   a真做b
a || b     a假做b
a && b || c  a真做b,a假做c


arrow
arrow
    全站熱搜

    痞客興 發表在 痞客邦 留言(0) 人氣()