shell脚本作业
1、输出99乘法表
方法一:
#for i in {1..9}
#do
# for j in {1..9}
# do
# if [ $j -le $i ]
# then
# echo -n " ${j}x${i}=$(($i*$j)) "
# fi
# done
# echo
#done
方法二:
#for ((i=1;i<=9;i++))
#do
# for ((j=1;j<=$i;j++))
# do
# echo -n " ${j}x${i}=$(($i*$j)) "
# done
# echo
#done
2、输出以下形状
(1)*
**
***
****
*****
******
*******
********
*********
for ((i=1;i<=9;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n "*"
done
echo
done
(2)
*
***
*****
*******
*********
***********
*************
for ((i=1;i<=9;i++))
do
for ((j=9;j>=$i;j--))
do
echo -n " "
done
for ((j=1;j<=$i;j++))
do
echo -n "*"
done
for ((j=1;j<$i;j++))
do
echo -n "*"
done
echo
done
(3)
*************
*************
*************
*************
*************
*************
*************
for ((i=1;i<=9;i++))
do
for ((j=9;j>=$i;j--))
do
echo -n "*"
done
for ((j=1;j<=$i;j++))
do
echo -n "*"
done
echo
done
(4)
*
* *
* *
* *
* *
* *
* *
* *
* *
**************
i=1
while [ $i -le 10 ]
do
j=1
while [ $j -le $((10-$i)) ]
do
echo -n ' '
j=$(($j+1))
done
j=1
while [ $j -le $((2*$i-1)) ]
do
if [ $j -eq 1 -o $j -eq $((2*$i-1)) -o $i -eq 10 ]
then
echo -n "*"
else
echo -n ' '
fi
j=$(($j+1))
done
echo
i=$(($i+1))
done
exit 0
3、编写双色球脚本
echo "第19100期开奖结果 开奖日期:$(date +'%F %T')"
for i in {1..6}
do
num=$(expr $RANDOM % 33 + 1)
echo -en "\033[31m$num \033[0m"
done
echo -en "\033[34m$(expr $RANDOM % 16 + 1)\033[0m"
echo