分类:
2008-06-25 18:16:13
################################################
########## 测试数值 ##########
################################################
eq 数值相等。
ne 数值不相等。
gt 第一个数大于第二个数。
lt 第一个数小于第二个数。
le 第一个数小于等于第二个数。
ge 第一个数大于等于第二个数。
数值计算
expr 1 + (3 * 2)
自增
COUNT=0
COUNT=`expr $COUNT + 1`
自增的另外一种用法
COUNT=$[COUNT + 1]
################################################
########## 字符串数值 ##########
################################################
= 两个字符串相等
!= 两个字符串不等
-z 空串
-n 非空串
################################################
########## 逻辑操作符 ##########
################################################
-a 逻辑与
-o 逻辑或
! 逻辑否
################################################
########## 控制流 ##########
################################################
if 条件1
then
elif 条件2
then
fi
case 值 in
模式1)
命令1
...
;;
模式2)
命令2
;;
*)
缺省命令
;;
esac
for 变量名 in 列表
do
...
done
until 条件
命令1
...
done
while 条件
do
...
done
################################################
########## 文件状态测试 ##########
################################################
-b file
True if file is a Block special device.
-c file
True if file is a Character special device.
-d file
True if file is a Directory.
-e file
True if file Exists.
-f file
True if file is a regular File.
-g file
True if file has its set-group-id bit set.
-G file
True if file is owned by the current effective group id.
-k file
True if file has its "sticky" bit set.
-h file
-L file
True if file is a symbolic Link.
-O file
True if file is owned by the current effective user id.
-p file
True if file is a named Pipe.
-r file
True if file is readable.
-S file
True if file is a Socket.
-s file
True if file has a Size greater than zero.
-t [FD]
True if FD is opened on a terminal. If FD is omitted, it defaults
to 1 (standard output).
-u file
True if file has its set-user-id bit set.
-w file
True if file is writable.
-x file
True if file is executable.
file1 -ef file2
True if file1 and file2 have the same device and inode numbers,
i.e., if they are hard links to each other.