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…