判斷
[root@VM-12-15-centos home]# vi test.sh
# 編寫如下
a=100
b=100
if test $[a] -eq $[b] ; then echo "true"; fi
# 執行
[root@VM-12-15-centos home]# sh test.sh
true
[root@VM-12-15-centos home]# vi test.sh
# 編寫如下
a=100
b=101
if test $[a] -eq $[b] ;
then echo "true"; else echo "false"; fi
# 執行
[root@VM-12-15-centos home]# sh test.sh
false
[root@VM-12-15-centos home]# vi test.sh
# 編寫如下
a=10
b=20
if (( $a == $b ))
then
echo "a 等於 b"
elif (( $a > $b ))
then
echo "a 大於 b"
elif (( $a < $b ))
then
echo "a 小於 b"
else
echo "沒有符合的條件"
fi
# 執行
[root@VM-12-15-centos home]# sh test.sh
a 小於 b
迴圈
for
[root@VM-12-15-centos home]# vi test.sh
# 編寫如下
for loop in 1 2 3 4 5
do
echo "The value is: $loop"
done
# 執行
[root@VM-12-15-centos home]# sh test.sh
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
[root@VM-12-15-centos home]# vi test.sh
# 編寫如下
for str in This is a string
do
echo $str
done
# 執行
[root@VM-12-15-centos home]# sh test.sh
This
is
a
string