String:
1. Single quotes:
str = ' value '
Single-Quote String restrictions:
Any character in a single quotation mark is output as is, and the variable in the single-quote string is not valid;
Single quotation marks cannot appear in single quote strings (not after using escape characters for single quotes);
2. Double quotes:
str = "value is \" ${name}\ "\ n"
str = "value is, ${name}\n"
Advantages of double quotes:
You can have variables in double quotes.
Escape characters can appear in double quotes
3. Get string length :
- String="ABCD"
- echo ${#string} #输出 4
4. To extract substrings:
- String="Alibaba is a great company"
- echo ${string:1:4} #输出liba
5. To find a substring:
- String="Alibaba is a great company"
- echo ' expr index ' $string ' is '
Array:
1. Defined:
Array_Name= (value0 value1 value2 value3)
2. Value:
${array_name[*]}
${array_name[@]}
Take all the elements
3. Get array Length:
- # Gets the number of array elements
- Length=${#array_name [@]}
- # or
- Length=${#array_name [*]}
- # Gets the length of an array of individual elements
- Lengthn=${#array_name [n]}
Shell strings and Arrays