免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1370 | 回复: 0
打印 上一主题 下一主题

Shell括号符号介绍 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-15 15:40 |只看该作者 |倒序浏览
[ 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 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
> 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
$


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90756/showart_1798380.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP