Shell案例:图案打印

打印三角形图案

#!/bin/bash
echo "Stars"
for (( i=1; i<=5; i++ ))
do
    for (( j=1; j<=i;  j++ ))
    do
     echo -n " *"
    done
    echo ""
done
for (( i=5; i>=1; i-- ))
do
    for (( j=1; j<=i;  j++ ))
    do
     echo -n " *"
    done
    echo ""
done

 

打印菱形案例

#!/bin/bash
MAX_NO=0
echo -n "Enter Number between (5 to 9) : "
read MAX_NO

if ! [ $MAX_NO -ge 5 -a $MAX_NO -le 9 ] ; then
   echo "???... I ask to enter number between 5 and 9, Try Again"
   exit 1
fi
clear

for (( i=1; i<=MAX_NO; i++ ))
do
    for (( s=MAX_NO; s>=i; s-- ))
    do
       echo -n " "
    done
    for (( j=1; j<=i;  j++ ))
    do
     echo -n " ."
    done
    echo ""
done

for (( i=MAX_NO; i>=1; i-- ))
do
    for (( s=i; s<=MAX_NO; s++ ))
    do
       echo -n " "
    done
    for (( j=1; j<=i;  j++ ))
    do
     echo -n " ."
    done
    echo ""
done
echo -e "Whenever you need help, I will always here"

 

使用帮助命令

 

cd命令:

格式:cd “路径/目录名”

1绝对路径:从根目录开始写,以“/”打头。

 2相对路径:当前目录的子级目录开始写。

例如:

cd  /home/z3切换到/home/z3r目录

cd /切换到根目录

cd ..切换到到上一级目录

cd ../..切换到上二级目录

cd ~切换到用户目录,比如是root用户,则切换到/root下

 

 

 

 

posted on 2018-10-28 11:26  阿小杜  阅读(1247)  评论(0编辑  收藏  举报