1.
#!/bin/bash
read -p "请输入一个字符:" num
case $num in
[[:lower:]])
echo "是小写字母"
;;
[[:upper:]])
echo "是大写字母"
;;
*)
echo "是数字"
;;
esac
2.
#!/bin/bash
read -p "请输入年" year
read -p "请输入月" month
case $month in
1)
echo 31
;;
2)
if [ $((year%4)) -eq 0 -a $((year%100)) -ne 0 -o $((year%400)) -eq 0 ]
then
echo 29
else
echo 28
fi
;;
3)
echo 31
;;
4)
echo 30
;;
5)
echo 31
;;
6)
echo 30
;;
7)
echo 31
;;
8)
echo 31
;;
9)
echo 30
;;
10)
echo 31
;;
11)
echo 30
;;
12)
echo 31
;;
esac
3.
#!/bin/bash
i=0
for i in `seq 100 1 1000`
do
ge=i%10
shi=i/10%10
bai=i/100
if [ $[$((ge**3))+$((shi**3))+$((bai**3))] -eq $i ]
then
echo "$i是水仙花数"
else
continue
fi
done
4.
#!/bin/bash
read -p "请输入:" a
read -p "请输入:" b
read -p "请输入:" c
arr=([1]=$a [9]=$b [15]=$c)
i=0
sum=0
for i in a b c
do
((sum+=i))
done
echo $sum
5.
#!/bin/bash
i=0
count1=0
count2=0
for i in `ls ~`
do
if [ -d ~/$i ]
then
((count1++))
elif [ -f ~/$i ]
then
((count2++))
fi
done
echo "目录文件个数为$count1"
echo "普通文件个数为$count2"
6.
#!/bin/bash
read -a arr
len=${#arr[*]}
for((i=1;i<=len-1;i++))
do
temp=0
for((j=0;j<len-i;j++))
do
if [ ${arr[j]} -gt ${arr[j+1]} ]
then
temp=${arr[j]}
arr[j]=${arr[j+1]}
arr[j+1]=$temp
fi
done
done
echo ${arr[*]}
7.
#!/bin/bash
read -p "请输入成绩:" score
if [ $score -gt 100 -o $score -lt 0 ]
then
echo "输入不合理"
else
case $score in
9?|100)
echo A
;;
8?)
echo B
;;
7?)
echo C
;;
6?)
echo D
;;
*)
echo 不及格
esac
fi