六十五. 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]#