1. Echo Parameters
- -N does not wrap (default line feed)
- -E makes the transfer character valid
Example
Ss = 'abc \ n' echo-e $ ssabc # echo $ ssabc
2. When assigning values = do not include spaces on both sides
A = "hello" # error A = "hello"
3. Shell operations
b=4let "c=$b+1"echo $c
4. Differences between single quotes and double quotes
Single quotation marks and double quotation marks are the same as string delimiters, rather than character delimiters. The single quotation mark is used to keep the literal value of all characters in the quotation marks, even if the \ and carriage return in the quotation marks are no exception.
Example
bb="hello"echo "$bb"helloecho ‘$bb‘$bb
Note that the ecoh-e '$ BB' result is still $ BB, because '$ BB' is the literal value and will not be escaped.
5. Array
5.1 declaration and definition
- Array ['a'] = 1
- Array = ('A', 'B ')
- Array = ([1] = 'A' [2] = 'B ')
5.2 access
- Echo $ {array ['a']}
- Echo $ {array [0]}
5.3 Traversal
for var in ${array[*]}do echo $vardone
5.4 array Length
num=${#array[@]}
Comparison: get String Length: num =$ {# STR}
6. multithreading in Linux Shell
for ((i=0;i<5;i++)); do{ sleep 3; echo "hello" $i}donewait
Comparison
for ((i=0;i<5;i++)); do{ sleep 3; echo "hello" $i}&donewait
This adds a background execution & symbol to the above. At this time, five cyclic tasks are executed concurrently, and at last it takes more than 3 seconds (the effect is very obvious ). The purpose of wait is to execute all the tasks in the background, otherwise the program will wait.
7. Remove '\ R' from the last row'
'\ R' at the end of the string is very disgusting. You can use the tr command to remove it.
A = "Hello \ r" Echo $ A | tr-d' \ R' Hello \ recho $ A | tr-d "\ r" Hello \ recho-e $ A | tr -d' \ r'hello # Transfer Character function echo-e $ A | tr-d "\ r" Hello
8. Compile the shell file
bash -x ***.sh
+ Starts with the intermediate compilation process, and the output without + is normal. The effect is very obvious.
Shell Command sorting