码迷,mamicode.com
首页 > 系统相关 > 详细

linux 控制结构

时间:2017-09-20 14:54:01      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:images   ash   bash   png   技术分享   gre   read   bsp   .com   

技术分享

技术分享

 注:

格式1、格式2:一个条件一个命令;

格式3:一个条件两个命令;

格式4:两个条件三个命令,注意条件的写法。

 

例1:

#!/bin/sh
#ifTest
#to show the method of if
echo -e "Enter the first integer:\c"
read FIRST
echo -n "Enter the second integer:"
read SECOND
if [ "$FIRST" -gt "$SECOND" ]
then
echo "$FIRST is greater than $SECOND"
elif [ "$FIRST" -lt "$SECOND" ]
then
echo "$FIRST is less than $SECOND"
else
echo "$FIRST is equal to $SECOND"
fi

执行:

[root@cdh1 sh]# ./test.sh
Enter the first integer:7
Enter the second integer:7
7 is equal to 7
[root@cdh1 sh]# ./test.sh
Enter the first integer:8
Enter the second integer:7
8 is greater than 7
[root@cdh1 sh]#

 例2:

#!/bin/bash
#5.sh
declare
a STRING;
b STRING;
BEGIN
a=$1
b=$2
if [ "$a" = "$b" ] ;then
echo "a=b"
else
echo "a!=b"
fi
END;

 

linux 控制结构

标签:images   ash   bash   png   技术分享   gre   read   bsp   .com   

原文地址:http://www.cnblogs.com/cxhfuujust/p/7560814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!