In my resume, I wrote that I am familiar with common Linux commands and can do shell programming, so it is necessary to learn shell programming.
Read the catalogue:
First, Shell and bash
The shell is the interface program that the user interacts with the Linux operating system kernel, and is also a command language interpreter, which interprets the commands entered by the user to the Linux kernel.
? There are many kinds of shells, common with Bourne shell (/usr/bin/sh or/bin/sh), Bourne Again Shell (/bin/bash), C Shell (/usr/bin/csh), K Shell (/usr/ Bin/ksh), Shell for Root (/sbin/sh), and so on.
Bash is a shell and is the default shell used by most Linux systems.
II. structure and execution of shell scripts
1. Script format
Scripting with the VI editor? The format is fixed, as follows:
#!/bin/sh? #! tells the system that the program specified later in the path is the shell program that interprets this script file.
#comments//Comment lines
Your commands go here
2. Execute the Script
After editing the script, save the file name filename.sh, and before running this script, you need to modify the executable permissions for this script:
Chmod+x fi?lename.sh
Execute script:
./filename.sh
3. The simplest Hello World program
#!? /bin/sh
A= "Hello World"; Variable Assignment variable_name = Variable_value
echo $a;? Use variable $variable or ${variable}
Iii. loops, if judgments, functions in the shell
1. For loop?
For I in $ (SEQ 0 5);d o
echo $i?
Done?
2.while Cycle
while condition; do
Command
Done
For example: a=10
While? [$a-ge 1];d o
? Echo $a
a=$[$a-1?]
Done
3. If judgment statement; Then command fi
if Judgment statement; Then command
Else? Command
Fi
If judgment statement one; then command
Elif Judgment Statement two; Then command
else command
Fi
if ((a<5)) is equivalent to if[$a-lt 5]? -lt less than
if ((a>5))? Equivalent to if[$a-GT 5]-gt greater than
if ((a>=5)) is equivalent to if[$a-ge 5]-ge greater than or equal
if ((a<=5)) is equivalent to if[$a-le 5]-le less than or equal to
if ((a==5)) is equivalent to if[$a-eq 5]-eq equals
if ((a!=5))? Equivalent to if[$a-ne 5]-ne not equal to
Determine the size of the value in addition to (()) The form, you can also use []?
? The mathematical calculation is to be enclosed in [] and a $ is taken outside.
A=1
b=2
sum=$[$a + $b]?
4. Functions in shell scripts
Function name () {
Command
}
In a shell script, the function is written in front.
function sum () {
SUM=$[$1+$2]
Echo $sum
}
Sum $?
Shell Programming (i)