如来神掌第二式第七招----典型shell示例
###############################################################################
#
Name : Mahavairocana
#
Author : Mahavairocana
#
QQ : 10353512
#
WeChat : shenlan-qianlan
#
Blog : http://www.cnblogs.com/Mahavairocana/
#
Description : You are welcome to reprint, or hyperlinks to indicate the
#
source of the article, as well as author
information.
###############################################################################
示例1 九九乘法表
#!/bin/bash for((i=1;i<=9;++i)) do for((j=1;j<=i;j++)) do echo -ne "$i*$j=$((i*j))\t" done echo done #!/bin/bash for i in $(seq 1 9);do for j in $(seq 1 ${i}) ;do echo -n -e "${j}x${i}=$(expr ${i} \* ${j})\t"; done ; echo ; done
示例2 加法表
#!/bin/bash for i in $(seq 1 9) do for n in $(seq 1 $i) do m=$(($i+$n)) echo -n "$i+$n=$m " done echo done
示例3 IP检测
#!/bin/bash IP=$1 if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] then for i in $(echo $IP | tr '.' ' ') do if [ $i -gt 255 ] then echo no && exit fi done echo yes else echo no fi
示例4 三角形
#!/bin/bash num=5 for i in $(seq 1 $num) do for x in $(seq 1 $(($num-$i))) do echo -n " " done for x in $(seq 1 $i) do echo -n "*" done echo done
示例5 金字塔
#!/bin/bash num=20 for i in $(seq 1 $num) do for x in $(seq 1 $(($num-$i))) do echo -n " " done for x in $(seq 1 $((2*$i-1))) do echo -n "*" done echo done
示例6 画斜线
#!/bin/bash num=10 for i in $(seq 1 $num) do for x in $(seq 1 $(($num-$i))) do echo -n " " done echo "*" done
posted on 2018-01-14 21:22 Mahavairocana 阅读(227) 评论(0) 编辑 收藏 举报