Positional variables
$ A Gets the file name of the current user script contains the path
$n gets the nth parameter of the currently executing shell script if n is greater than 9 in curly braces ${10}
$# gets the number of arguments for the currently executing shell script
$? Check if the last command is successful, if 0 is returned successfully
0 successes
2 Permission denied
125 script Run Error system related
126 Command not executed
127 No commands to execute
>128 command is forcibly stopped by the system
$$ Process number
BaseName the name of the script
DirName $ $ Script Path
Character matching
${#string} Returns the length of the $string
${string:position} in string, starting from position $position to extract string
${string:position:length} in string, starting from position $position to extract substring of length $length
${string##} removed from the beginning
${string%substring} removed from the end
${STRING/SUBSTRING/REPLAC} replace $replac first match replace $substring
${STRING/%SUBSTRING/REPLAC} replaces $replac first match replacement $substring from the end
${string/#SUBSTRING/replac} replaces $replac first match replacement $substring from the beginning
Wd= "I am a Boy"
echo ${#WD} print string length
Echo ${wd:2} returns after the first character
echo ${wd}|wc-m can also print character lengths
Echo ${wd:0:3} Starts from the No. 0 and takes three
echo ${wd}|cut-c 1-5 take 1-5
Echo ${wd#i} removes the shortest character I from the beginning
echo ${wd# #I} remove the longest character from the beginning I
echo ${wd/i Am/you is} first match replace
Echo ${wd/#} matches from the beginning
Echo ${wd/%} matches from the end
Rename
Defining variables
1.
${value:-word} detects an empty variable and prints it if $string is not defined position
Result=${value:-word}
T=${cron_value:-unset}
["$t"! = "UNSET"] && export cron_value= "$t"
Find ${path:=/tmp/}-name *.tar.gz-type-f |xargs rm-rf
2.
${value:=word} If the variable is not defined, the value is assigned to the variable.
3.
${value:? " Message "} If the variable name exists and is not NULL, the value of the variable is returned. Otherwise, the variable name is displayed: Message
4.
${value:+word} returns Word if the variable name exists and is not NULL, otherwise null is used to detect whether the variable is defined
5.
${value-word} If the variable does not exist in Word instead of vsftpd the following is useful to
SHELL Variable Summary