热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

当前位置 :| 主页>Linux教程>Shell开发>

Linux中if语句的使用

来源: 作者: 时间:2007-12-19 Tag: 点击:
常用运算符

-eq ==

-ne !=

-lt <

-le <=

-gt >

-ge >=

<li>编写一脚本if.sh

#!/bin/sh

if test $1 -eq $2; then

  echo $1 '==(-eq)' $2

else

  if test $1 -ne $2;then

    echo $1 '!=(-ne)' $2

  fi

  if test $1 -lt $2;then

    echo $1 '<(-lt)' $2

  fi

  if test $1 -gt $2;then

    echo $1 '>(-gt)' $2

  fi

fi

<li>运行如下

chmod a+x if.sh

命令:./if.sh 2 2

结果:2 ==(-eq) 2

命令:./if.sh 1 2

结果:1 !=(-ne) 2

  1 <(-lt) 2

命令:./if.sh 2 1

结果:2 !=(-ne) 1

  2 >(-gt) 1


最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册