第一题
#!/bin/bash
read -p "Please input Number: " n
declare -i n=$n
declare -i sum=0
while [ "$n" -ne "0" ]
do
sum=$sum+$n%10
n=$n/10
done
echo $sum
第二题
#!/bin/bash
read -p "Please input an intenger number: " tmpnum
i=0
while [ $tmpnum -ne "0" ]
do
tmpnum1[$i]=`echo ${tmpnum}%10|bc`
tmpnum=`echo ${tmpnum}/10|bc`
((i++))
done
for i in `seq $i`
do
echo -n ${tmpnum1[$i-1] }
done
第三题
#!/bin/bash
read -p "Please input the dirctory which you want to backup: " backdir
echo "The backup dir is $backdir `uptime`" >>log.txt
read -p "Please input the time when you want to backup:
first input the mintue " backtime_m
read -p "Please input the time when you want to backup:
second input the hours " backtime_h
echo "It will backup at $backtime_h:$backtime_m everyday `uptime`" >>log.txt
read -p "Please input the dirctory which you want your backupfile export to : " exportdir
echo "The backup file will be saved to $exportdir " >>log.txt
echo ""$backtime_m" "$backtime_h" * * * /bin/tar -zcvf backup_`date +%m_%d_%H%M%S`.tar.gz "$backdir" -C $exportdir >>log.txt && /usr/bin/uptime >>log.txt " >>/var/spool/cron