testコマンド

文字列比較

 "A" = "A"  
 "A" != "B"  
 -n "A" (文字列は空でない)
 -z ""  (文字列は空)

数値比較

 1 -eq 1
 2 -gt 1
 2 -ge 2
 1 -lt 2
 2 -le 2
 2 -ne 1

ファイル評価

 -f file
 -d dir
 -r file (読み込み可能)
 -w file (書き込み可能)
 -x file (実行可能)
 -s file (サイズ0以上)

論理演算子

 1 -a 1
 0 -o 1

否定

 if [ ! -f /tmp/1.txt -a ! -f /tmp/2.txt ]; then
  echo "no 1.txt, no 2.txt"
 fi

参考


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS