Sharing a few shell programming, easy to Review of linux
1. The user determines whether the input number palindrome
1 #!/bin/bash
2 read in
3 res=`echo $in|rev`
4 if [ $res -eq $in ]
5 then
6 echo "$in is a huiwenshu!" 7 elif [$ in $ res -what ]
8 then 9 echo "$in not is a huiwenshu" 10 fi
2. Calculate the factorial of a number of user input
1 #!/bin/bash 2 sum=1 3 i=1 4 read n 5 while [ $i -le $n ] 6 do 7 sum=$[$sum*$i] 8 i=$[$i+1] 9 done 10 echo "sum=$sum"
3. The user input is determined whether the number is a prime number
1 #!/bin/bash 2 read num 3 declare -i count=0 4 for n in `seq 1 $num` 5 do 6 if [ $((num%n)) -eq 0 ] 7 then 8 count=$[$count+1] 9 fi 10 done 11 if [ $count -eq 2 ] 12 then 13 echo "$num is a prime num" 14 else echo "$num not is a prime num" 15 fi
Item 4. The first n Fei not calculate the number of columns that the wedge and
1 #!/bin/bash 2 read num 3 a=1 4 b=1 5 c=0 6 sum=0 7 for((i=0;i<num;i++)) 8 do 9 echo "$a" 10 let sum+=a 11 let c=a+b 12 let a=b 13 let b=c 14 done 15 echo "sum=$sum"