韩顺平Linux网课笔记(65到67)

六十五. shell流程控制if

[root@localhost opt]# cat test1.shell 
#!/bin/bash

if [ $1 -ge 60 ]
then
	echo "pass the exam"
elif [ $1 -lt 60 ]
then
	echo "not pass"
fi

六十六. shell流程控制case

[root@localhost opt]# vim testCase.sh
[root@localhost opt]# chmod 744 testCase.sh 
[root@localhost opt]# ./testCase.sh 1
Monday
[root@localhost opt]# ./testCase.sh 2
Tuesday
[root@localhost opt]# ./testCase.sh 5
other
[root@localhost opt]# 
[root@localhost opt]# cat testCase.sh 
#!/bin/bash

case $1 in 
"1")
echo "Monday"
;;
"2")
echo "Tuesday"
;;
*)
echo "other"
;;
esac

六十七. shell流程控制for

[root@localhost opt]# vim testFor.sh 
[root@localhost opt]# ./testFor.sh 10 20 03 40
the num is 10 20 03 40
 
the num is 10
the num is 20
the num is 03
the num is 40
[root@localhost opt]# cat testFor.sh 
#!/bin/bash


#use $*
for i in "$*"
do
	echo "the num is $i"
done

echo " "

#use $@
for j in "$@"
do
	echo "the num is $j"
done
[root@localhost opt]# 

 

[root@localhost opt]# vim testFor2.sh
[root@localhost opt]# ./testFor2.sh
sum=5050
[root@localhost opt]# cat testFor2.sh
#!/bin/bash

# calculate from 1 to 100

SUM=0
for((i=1;i<=100;i++))
do
	SUM=$(($SUM+$i))
done

echo "sum=$SUM"
[root@localhost opt]# 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值