1. Data type:
String
Array
2. Naming conventions for variables:
Can only start with a-Z or a-Z
Cannot have spaces in the middle, you can use _
Punctuation cannot be used
Cannot use the SHELL keyword
3. Variable type:
Environment variables
Local variables
Shell variables
4. String
Strings are the most common and useful data types in shell programming (except numbers and strings, and no other type works well), strings can be in single quotes or double quotes, or without quotes. The difference between single and double quotes is similar to PHP.
Single quotes:
Output exactly as quoted, invalid internal variable, invalid escape character
Double quotes:
Internal variables can be parsed, escape characters can appear
Stitching characters
Name='liupf'echo"$name Echo " Hello ${name} "
Get string length
Name="liupf" echo ${#name}
Intercept string
$name ='liupf' echo ${name:1:3}
Find sub-string location
string=My name is LIUPF echo 'expr'$string" Is '
Array
1, the shell uses () to represent the array, the elements are separated by a space. The basic form is expressed as:
A, array name = (value 0 value 1 value 2 value N)
B, array name = (
Value 0
···
Value n
)
C, array name [0]= value 0
Array name [...] =··· Value
Array name [n]= value 2
2. Reading the value of an array
${array name [table below]}
3. Get all the values of the array
${array name [@]}
4. Get the length of the array
${#数组名 {@}}
${#数组名 {*}}
${#数组名 {n}}
Shell Basics Learning (ii) Shell variables