Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4826162
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2010-11-15 19:00:52

perl 跟 bash刚好相反。。。。

Perl comparison
Refer to

Numerical Comparison
< less than $bad = $gpa < 1.5;
<= less than or equal $good = 3.5 <= $gpa;
> greater than $very_good = $gpa > 3.9;
>= greater than or equal $not_bad = $gpa >= 2.3;
== equals to $perfect = $gpa == 4;
!= not equal to $not_perfect = $gpa != 4;
<=> compare. The result of this operator is equal to either 1, 0, or -1. It's equal to 1 if the first operand is greater than the second, zero if they are equal, and -1 if the second is greater than the first. $comparison = $a <==> 123;
String Comparison
lt less than $before = $name lt "b";
le less than or equal $a_name = $name le "a";
gt greater than $after = $name gt "Tester";
ge greater than or equal $after_P = $name ge "O";
eq equivalent to $is_Bob = $name eq "Bob";
ne not equal to $not_Bob = $name ne "Bob";
cmp The string comparison operator evaluates to either 1, 0, or -1. $comparison = $name cmp "Bob";


Bash comparison

Refer to

[ "$shvar" = "fox" ]     String comparison, true if match.
[ "$shvar" != "fox" ] String comparison, true if no match.
[ "$shvar" = "" ] True if null variable.
[ "$shvar" != "" ] True if not null variable.

[ "$nval" -eq 0 ] Integer test; true if equal to 0.
[ "$nval" -ge 0 ] Integer test; true if greater than or equal to 0.
[ "$nval" -gt 0 ] Integer test; true if greater than 0.
[ "$nval" -le 0 ] Integer test; true if less than or equal to 0.
[ "$nval" -lt 0 ] Integer test; true if less than to 0.
[ "$nval" -ne 0 ] Integer test; true if not equal to 0.

[ -d tmp ] True if "tmp" is a directory.
[ -f tmp ] True if "tmp" is an ordinary file.
[ -r tmp ] True if "tmp" can be read.
[ -s tmp ] True if "tmp" is nonzero length.
[ -w tmp ] True if "tmp" can be written.
[ -x tmp ] True if "tmp" is executable.

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