shell脚本画五角星
时间: 2023-11-14 20:09:50 浏览: 263
好的,以下是画五角星的shell脚本:
```shell
#!/bin/bash
# 画五角星
for ((i=0; i<5; i++))
do
echo -n "* "
done
echo ""
for ((i=0; i<2; i++))
do
for ((j=0; j<4-i; j++))
do
echo -n " "
done
echo -n "* "
for ((j=0; j<i*2-1; j++))
do
echo -n " "
done
echo "*"
done
for ((i=0; i<3; i++))
do
for ((j=0; j<i+1; j++))
do
echo -n " "
done
echo -n "* "
for ((j=0; j<5-i*2; j++))
do
echo -n " "
done
echo "*"
done
for ((i=0; i<5; i++))
do
echo -n "* "
done
echo ""
```
相关问题
五角星shell脚本
五角星的Shell脚本可以用来打印一个五角星图案。下面是一个示例的五角星Shell脚本:
#!/bin/bash
# 打印五角星
echo "输出五角星图案"
for (( i1=1;i1<6;i1 )) # 这是五角星的上面一个角
do
let c=19-$i1
for (( j1=1;$j1<$c;j1 )) # 这是空格
do
echo -n " "
done
let d=2*$i1-1
for (( k1=1;$k1<=$d;k1 )) # 这是“*”
do
echo -n "*"
done
echo
done
for (( i2=1;i2<5;i2 )) # 这是五角星的中间两个角
do
let e=3*$i2-3
for (( j2=1;$j2<$e;j2 ))
do
echo -n " "
done
let f=42-6*$i2
for (( k2=1;$k2<=$f;k2 ))
do
echo -n "*"
done
echo
done
for (( i3=1;i3<3;i3 )) # 这是中间与下部相接的部分
do
let g=12-$i3
for (( j3=1;j3<$g;j3 ))
do
echo -n " "
done
let h=12+2*$i3
for (( k3=1;k3<=$h;k3 ))
do
echo -n "*"
done
echo
done
for (( i4=1;i4<5;i4 )) # 这是五角星的下面两个角
do
let o=10-$i4
for (( j4=1;j4<$o;j4 ))
do
echo -n " "
done
let p=10-2*$i4
for (( k4=1;k4<=$p;k4 ))
do
echo -n "*"
done
let q=6*$i4-3
for (( m4=1;m4<$q;m4 ))
do
echo -n " "
done
for (( n4=1;n4<=$p;n4 ))
do
echo -n "*"
done
echo
done
echo " * *" # 盖上角 最后是这么个结果
此Shell脚本可以在bash环境下运行,打印出一个五角星图案。它使用了循环和条件语句来控制空格和星号的输出位置,从而形成五角星的形状。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [ToolsPentest:Ferramentas criadas em Python,Shell脚本,C e JavaScript para Pentest](https://download.csdn.net/download/weixin_42112685/15324699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [教你使用shell脚本打印五角星](https://blog.csdn.net/empty_csx/article/details/114597376)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [shell脚本练习之——形状练习(菱形、直角三角形、等腰三角形、五角星)](https://blog.csdn.net/Lucien010230/article/details/114594259)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
使用shell脚本打印四行四列五角星
要使用shell脚本打印四行四列五角星,可以参考以下代码:
```
#!/bin/bash
# 打印五角星
for ((i=1;i<=4;i++))
do
for ((j=1;j<=4;j++))
do
for ((i1=1;i1<6;i1++)) # 这是五角星的上面一个角
do
let c=9-$i1
for ((j1=1;j1<$c;j1++)) # 这是空格
do
echo -n " "
done
let d=2*$i1-1
for ((k1=1;k1<=$d;k1++)) # 这是“*”
do
echo -n "*"
done
echo
done
for ((i2=1;i2<3;i2++)) # 这是中间与下部相接的部分
do
let g=6-$i2
for ((j3=1;j3<$g;j3++))
do
echo -n " "
done
let h=6+2*$i2
for ((k3=1;k3<=$h;k3++))
do
echo -n "*"
done
echo
done
for ((i4=1;i4<3;i4++)) # 这是五角星的下面两个角
do
let o=5-$i4
for ((j4=1;j4<$o;j4++))
do
echo -n " "
done
let p=5-2*$i4
for ((k4=1;k4<=$p;k4++))
do
echo -n "*"
done
let q=6*$i4-3
for ((m4=1;m4<$q;m4++))
do
echo -n " "
done
for ((n4=1;n4<=$p;n4++))
do
echo -n "*"
done
echo
done
echo " * *" # 盖上角
done
done
```
阅读全文