#!/bin/bash
read -p "请输入一个无符号整数>>>" num
for ((i=1;i<=${#num};i++))
do
echo -n "${num:0-$i:1}"
done
echo ""
#!/bin/bash
n=0
bc=0
sc=0
read -p "请输入一个字符串>>>" str
for ((i=0;i<${#str};i++))
do
case ${str:$i:1} in
[0-9])
((n++))
;;
[a-z])
((sc++))
;;
[A-Z])
((bc++))
;;
*)
;;
esac
done
echo "该字符串中大写字母有$bc个,小写字母有$sc个,数字有$n个"
#!/bin/bash
while true
do
read -p "请输入年月日(eg:2022/7/15)>>>" str
year=`echo $str | cut -d / -f 1`
month=`echo $str | cut -d / -f 2`
day=`echo $str | cut -d / -f 3`
if test $(( (year%4==0 && year%100!=0) || (year%400==0) )) -eq 1
then
flag=1
else
flag=0
fi
if test $month -lt 1 -o $month -gt 12
then
echo "month error(1<=month<=12),try again"
continue
fi
if test $day -lt 0
then
echo "day error(day>=1),try again"
continue
else
case $month in
1|3|5|7|8|10|12)
if test $day -gt 31
then
echo "day error(day<=31),try again"
continue
fi
;;
4|6|9|11)
if test $day -gt 30
then
echo "day error(day<=30),try again"
continue
fi
;;
*)
if test $flag -eq 1 -a $day -gt 29
then
echo "day error(day<=29),try again"
continue
elif test $flag -eq 0 -a $day -gt 28
then
echo "day error(day<=28),try again"
continue
fi
;;
esac
fi
break
done
count=0
for ((i=1;i<month;i++))
do
case $i in
1|3|5|7|8|10|12)
((count+=31))
;;
4|6|9|11)
((count+=30))
;;
*)
if test $flag -eq 1
then
((count+=29))
else
((count+=28))
fi
;;
esac
done
((count+=day))
echo "该日期是$year年的第$count天"