Bash is currently a more popular type of shell under Linux, and the following are some of the scattered things that are recorded in the learning process. Tidy up for forgetting!
1. Transfer of function parameters
1) Variables in the script that precede the function definition are available in the function
2) function to run the required parameters, can be $, $, $ ... To pass
3) Variable settings keywords should avoid system variables to avoid errors
4) keyboard reading of variables
READ-P/-T variable
-P Follow-up prompt
Number of seconds to wait after-t
Reference script (command) parameters
The $ A Script (command) itself
The first logarithm of a script (command)
$
$? Read exit code of last execution command, 0 for success other for failure
2.bash arrays
Statement
DECLARE _a array
(You can also assign a variable directly to an array by not declaring it.)
Assign value
1) array = (var1 var2 var3 ...)
2) array = ([0]=var1 [2]=var2 ... )
3) Array[0]=var1
referencing arrays
Echo ${array[n]}
Iterating through an array
Filename= (' ls ')
For Var in ${filename[@]};d o #@/*---expansion position logarithm, starting from 1
Echo $var
Done
Various symbols in the 3.shell
code block
{} Unable to open a new shell properly
[]test,test's expression will be in []. [] is part of the shell built-in test command, not a connection to the/usr/bin/test, [followed by a space,] a space before
[] array elements
[] Character Range
(()) Data calculation extension, (()) using a numeric calculation
"" Strong reference (preserves whitespace in the variable)
' Weak references '
Meaning of the 4.bash exit code
1 General error
2shell built-in command use error
126 command call cannot be performed
127command not found
Parameter Error in exit
130 using Ctr+c to end the script
255 out of range exit status
Ps:shell script is an administrator to complete the management of the server is very important content, the full use of the script can make you become a lazy administrator, this is the path to success.
Some tips in the shell