Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Shell script programming-output diamonds, triangles or digital pyramids (with flashing colors) according to the number of inputs

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Shell script programming-output diamonds, triangles or digital pyramids (with flashing colors) according to the number of inputs

The shell script and explanation are as follows

#! / bin/bash# creates an endless loop. If you enter an error or enter the "quit" string to exit the script while truedo# and wait for the user to enter read-p, enter a positive integer not greater than 20 (enter "quit" to exit): "n # first determine whether the string is quitif [" $n "= =" quit "] then echo" you choose to exit "exit 0fi# determines whether the input is numeric or not If not, the error termination script if [[$n = ~ ^ [0-9] + $]] then: else echo "sorry you input no a number!" Exit 1fi# determines whether the input number is greater than 20, then jump out of this cycle and enter the next cycle if [$n-gt 20] then echo "the number you entered is too large, I may not be able to execute" continue# indicates that the number entered is not more than 20 Determine whether it is odd or even elif [[$n% 2-eq 1]] # determine whether it is odd then echo "you entered an odd number" echo "will display n lines of diamond" let half= (echo) / 2 let otherhalf=half-1 # echo $half for i in `seq 1$ half` do for ((j=$half) J > ibomacher -) do echo-n "done for m in `seq 1$ i` do echo-ne"\ 033 [5Trac34m*\ 033 [0m "done echo done for i in `half1 $otherhalf`do for m in `seq $i`half` do echo-n"done for ((jobless others halfwitj > = I) ) do echo-ne "\ 033 [5 34m *\ 033 [0m" done echo doneelse echo "you entered an even number" # indicates that you entered an even number not less than 20 # to determine whether the even number is less than 10 if [$n-lt 10] then for i in `seq 1$ n` do for ((jobless than n` do for j > I) ) do echo-ne "" done for m in `seq 1$ i` do echo-ne "\ 033 [1x 36m done echo done # indicates that the even number not less than 20 is not less than 10 else for i in `m 1$ n` do for ((jacks seq 1$ n` do for) ) do echo-n "" done for m in `do echo 1$ i` do echo-n "*" done echo done fifidone

You can copy and understand a wave of things directly by yourself after execution.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report