Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1148431
  • 博文数量: 153
  • 博客积分: 10576
  • 博客等级: 上将
  • 技术积分: 2137
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-02 21:01
文章分类

全部博文(153)

文章存档

2009年(43)

2008年(110)

分类: LINUX

2008-11-29 19:52:20

[ expression ] 用于test操作

n1 -eq n2 Check if n1 is equal to n2.

n1 -ge n2 Check if n1 is greater than or equal to n2.

n1 -gt n2 Check if n1 is greater than n2.
n1 -le n2 Check if n1 is less than or equal to n2.
n1 -lt n2 Check if n1 is less than n2.
n1 -ne n2 Check if n1 is not equal to n2.
str1 = str2 Check if str1 is the same as string str2.
str1 != str2 Check if str1 is not the same as str2.
str1 < str2 Check if str1 is less than str2.
str1 > str2 Check if str1 is greater than str2.
-n str1 Check if str1 has a length greater than zero.
-z str1 Check if str1 has a length of zero.
-d file Check if file exists and is a directory.
-e file Checks if file exists.
-f file Checks if file exists and is a file.
-r file Checks if file exists and is readable.
-s file Checks if file exists and is not empty.
-w file Checks if file exists and is writable.
-x file Checks if file exists and is executable.
-O file Checks if file exists and is owned by the current user.
-G file Checks if file exists and the default group is the same as the current user.
file1 -nt file2 Checks if file1 is newer than file2.
file1 -ot file2 Checks if file1 is older than file2.

(( expression )) 用于数值计算

val++ post-increment
val-- post-decrement
++val pre-increment
--val pre-decrement
! logical negation
∼ bitwise negation
** exponentiation
<< left bitwise shift
>> right bitwise shift
& bitwise Boolean AND
| bitwise Boolean OR
&& logical AND
|| logical OR

[[ expression ]] 高级的字符串比较 支持正则表达式

示例:
$ cat test
#!/bin/bash
# using pattern matching
if [[ $USER == r* ]]
then
echo "Hello $USER"
else
echo "Sorry, I don’t know you"
fi
$ ./test
Hello rich
$


阅读(1503) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

kidding2008-12-11 16:00:02

bei lou shang de zheng bengkui le

chinaunix网友2008-12-07 20:33:06

Wo shi ge lao wai ,ni xie de bucuo! zai women de guojia you hen duo ren kan ni de blog o!

chinaunix网友2008-12-07 20:33:02

Wo shi ge lao wai ,ni xie de bucuo! zai women de guojia you hen duo ren kan ni de blog o!