In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to achieve process control in Shell, I hope you have something to gain after reading this article, let's discuss it together!
Shell process control
In Linux programming, flow control statements are basically control statements of if, for, while, until, case and other conditions.
If control
Common grammatical structures of if
If (expression); then echo .else echo .fi
Demo:
#! / bin/bashnum=10if ((${num} > 4)); thenecho "${num} greater than 3" fiif test [${num} > 4]; thenecho "${num} greater than 4" fiif multiple judgments #! / bin/bashnum=10;if [$num-lt 8]; thenecho "${num} less than 8" elif [${num}-eq 10]; thenecho "${num} equals 10" elif [${num}-gt 11] Then echo "${num} > 10" else echo "does not meet the condition" fi;for loop
For loop syntax structure
For variable in string do echo "" done
Demo:
#! / bin/bash# defines an array val= (1 2 3 4 56) for i in ${val [*]} # or you can directly in `seq 6`do echo "this is num: $I" done
Output result:
# print result: this is num: 1this is num: 2this is num: 3this is num: 4this is num: 5this is num: 6
Demo 2:
#! / bin/bash # batch package for i in `find / var/log-name "* .log" `do tar-czf 2019log.tgz $I donewhile loop for lookup files
While grammatical structure
While (conditional judgment) do echo "" done
Demo:
#! / bin/sh iTunes 1; while ($I
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.