Chinaunix首页 | 论坛 | 博客
  • 博客访问: 567873
  • 博文数量: 213
  • 博客积分: 6789
  • 博客等级: 准将
  • 技术积分: 1947
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-01 17:11
文章分类

全部博文(213)

文章存档

2012年(9)

2011年(62)

2010年(99)

2009年(43)

分类:

2009-09-30 09:22:40

文件检验

-b filename      特定块文件
-c filename      特定字符文件
-d filename      目录文件
-e filename      文件存在
-f filename      非目录普通文件存在
-L filename      文件是一个符号链接

-n string        如果string长度非零则为真
-p filename      文件是一个管道
-r filename      文件可读
-w filename      文件可写
-x filename      文件可执行

-z string        如果string长度为零则为真

if命令:
 
if command
then
   command
   cmomand
fi
----------------
 
if test expression
then
   command
fi
        or
if [ string/numeric expression ] then
   command
fi
-----------------
if [[ string expression ]] then
   command
fi
 
-----------------
if (( numeric expression))
 
例:
if (( $# != 2))
then
   echo "Usage: $0 mdays size" 1>&2
   exit1
fi
 
1>&2 打印错误信息到标准错误
 
null命令:
   null命令用冒号表示,是1个内建的什么都不做的命令,返回状态值为0,如果在if命令后面没有内容,同时又要避免产生错误信息,就需要在then后面写null语句。通常null命令作为loop命令的参数来建立一个无限循环。
if grep "$name" databasefile >& /dev/null
then
         :
else
    echo " a"
fi
 
case命令:
 
case variable in
value1)
    command(s)
    ;;
value2)
    command(s)
    ;;
*)
    command(s)
    ;;
esac
 
例:
case "$color" in
[Bb]l??)
    command
    ;;
[Gg]ree*)
    command
    ;;
red | orange)
    command
    ;;
*)
    command
    ;;
esac
 
color以B,b开头,然后是l和任意2个字符。
如果表达式以G,g开头,然后是ree和0个或者多个任意字符。
如果表达式是red或者orange。
阅读(696) | 评论(0) | 转发(0) |
0

上一篇:sudoer

下一篇:read declare let

给主人留下些什么吧!~~