In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-08 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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.