if
Multi-branch statement practice
#!/bin/bash
read-p " Please enter 100 m running seconds: "I
If [$i-lt] && [$i-GT 0]
Then
echo " Enter the final "
read-p " enter male and female "a
if [$a = male]
Then
echo " into the men's group "
elif [$a = female]
Then
echo " Enter the women's group "
Else
echo "Error"
Fi
elif [$i-ge 10]; Then
echo " elimination "
Else
echo " Error "
Fi
Case Statement Practice, automatically unzip the compressed file according to the filename suffix
Vim untar.sh
#!/bin/bash
Case $ in
*.gz)
If [-F $]
Then
TAR-ZXVF $1-c/opt
Fi
;;
*.BZ2)
If [-F $]
Then
TAR-JXVF $1-c/opt
Fi
;;
*)
echo " file format Error "
Esac
For integers less than 100 and
#!/bin/bash
Sum=0
read-p " Enter an integer less than 100: "N
If [$n-lt 100]; Then
For I in $ (seq 1 $n)
Do
Let sum= $sum + $i
Done
echo " from 1 to $n, so the number of integers is $sum "
Else
echo " input Error "
Fi
Odd and, even, and equal to less than 100
#for Statement Format
#!/bin/bash
Sum=0
For i in {1..100..2}
Do
Let sum= $sum + $i
Done
echo " Cardinality and = $sum "
Sum=0
For I in $ (SEQ 0 2 100)
Do
Let sum= $SUM + $i
Done
echo " Even and = $SUM "
#while Statement Format
#!/bin/bash
A=1
B=0
While [$a-le 100]
Do
If [' Expr $a% 2 '-eq 1]; Then
# if [$ ($a%2)-eq 1]; Then
Let b= $b + $a
Fi
Let a++
Done
echo " Cardinality and = $b "
A=1
C=0
While [$A-le 100]
Do
# if [' Expr $A% 2 '-eq 0]; Then
If [$ ($A%2)-EQ 0]; Then
Let c= $c + $A
Fi
Let a++
Done
echo " Even and = $c "
Shell Scripting Exercise A