File header
#!/bin/sh
Basic syntax:
Define variables:
Your_name= "Aivy"
In addition to explicitly assigning values directly, you can also assign a value to a variable using a statement:
for file in ' ls/etc ' or for file in $ (LS/ETC)
The above statement loops out the file name of the directory under/etc.
Pass Parameters && echo Print:
#!/bin/bashyour_name= "Aivy"' Your name: ' $your _name
Print results----> Your name: Aivy
Process Control Statements:
If Else
Note the point:
- else if there is no content, there is no need to write
- The final end needs to be added fi
#!/bin/Basha=10b=20if [$a = = $b ]then"a equals B"else "a Not equal to B "fi
For Loop
#!/bin/bash for loop in 1 2 3 4 5 Does "The value is: $loop" Done
Execution Result:
The value is:12345
While statement
#!/bin/shint=1while (($Int.<=5 ))do echo $ int" int++" Done
Execution Result:
12345
Until cycle
#!/bin/sha=0! $a-lt ]do echo $a "a++"
Done
Execution Result:
0123456789
Case
#!/bin/shanum=1 case $aNumin 1) echo ' You selected 1 ' ;; 2) echo ' You have chosen 2 ' ;; 3) echo ' You have chosen 3 ' ;; 4) echo ' You have chosen 4 ' ;; *) echo ' You did not enter a number between 1 and 4 ' ;; Esac
Execution Result:
You chose 1.
Shell (i)