Before the concept of variables and logical operators, you can write a judgment statement, but here note that the two sides of the brackets must be left blank, or error.
Operator
- Assignment, with a let statement, such as Let "a=1"
- Arithmetic operation, support +-*/% (modulo operation) * * (Power operation)
- Bitwise operators, support << (shift left) >> (Shift right) & (bitwise VS) | (bitwise OR) ~ (bitwise reversed) ^ (bitwise XOR)
If/then/else statements
Give me a chestnut, please.
#!/bin/bashread var1if ["$var 1"-gt]thenecho "$var 1 is greater than" else echo "$var 1 was less than" fi
Note: I heard that if else inside another nested if statement, you can consider using the Elif statement, this can reduce the number of fi, so that the structure is clear
Case statement
#!/bin/bashread dayweek= (Sunday Monday Tuesday Wednesday Thursday Friday Saturday) case $day in1) echo ${week[1]};; 2) echo ${week[2]};; 3) echo ${week[3]};; 4) echo ${week[4]};; 5) echo ${week[5]};; 6) echo ${week[6]};; 7) echo ${week[0]};; *) echo "No Such day ...";; Esac
For loop
There are four different formats, and there seems to be something else.
#!/bin/bashfor var1 in Mon Tue Wed Thu Fri Sat sundo Echo ' Today is $var 1 ' donefor var2 in {1..10..2}doecho ' this is $var 2 "Donefor Var3 in $ (SEQ 1 2) Doecho" I had a/an $var 3 "Donefor VAR4 in $ (LS) Doecho" Here's the file $var 4 "done
While loop
#!/bin/bashi=1while ((I <= 5)) Doecho "i = $i" let "+ + i" done
SELECT statement
This SELECT statement to the time the wood has seen, run when you can interact with the user, run the following program to understand. If you don't break it, you're going to die.
#!/bin/bashecho "which color do you like?" Select Var1 in red Green Bluedoecho "I like $var 1" breakdone
Getting Started with Linux Shell scripting (ii) Looping statements