Master the conditional branch structure of shell programming through several cases-linux operation and maintenance

Shell scripting is a skill that any back-end programmer should master. Today, let’s learn its conditional branch structure together, and then master it through several cases. First, let’s look at the basic structure of the shell script, which is as follows: #!/bin/bash Code Below, let’s write the simplest shell script. #!/bin/bash echo ‘hello world’ When the above program is executed, the hello world characters will be printed on the screen. Next, let’s take a look at the conditional branch structure. Shell scripts have if and case statements about conditional branches. if Like other programming languages, the if statement of the shell program , conditional branches are also divided into single branch, double branch and multi-branch. # Single branch if condition ;then … the fi # double branch if condition ;then … else … the fi # multi-branch if condition; then … elif condition; then … else … fi First of all, let’s use a simple example to practice and write a shell script. The function of this script is that when the user enters a score, the program outputs different comments through the score, failed, good , Excellent, etc. First of all, we need to prompt the user to enter…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索