Learning from Linux-using variables
1. Use $ to place the variable before it. For example, to separate echo $ PATH from other characters, use {} and "", for example, echo $ {PATH} nic echo "$ PATH" nic 2. variable definition Rule 1. the variable name can only contain English letters and numbers, but cannot start with a number. the variable and the variable content are connected with "=". The equal sign cannot be directly followed by a space character. The following error is returned: "myname = VBird" or "myname = VBird Tsai" 3. if there is a space character in the variable content, you can use double quotation marks "or single quotation marks" '"to combine the variable content. However, special characters such as $ in double quotation marks can retain the original features, special characters in single quotes are only general characters (plain text. use \ to convert special characters into general characters; 5. if you still need the information provided by other commands in a string of commands, you can use the unquoted "'directive '" or "$ (Directive )』. 'Is the key on the left of the number key 1 on the top of the keyboard, not the single quotation mark! For example, you can set the core version as follows: echo $ version 'version = $ (uname-r) '6. generally, uppercase characters are the default variables of the system. You can set the variables to lowercase characters 7. you can define an array and use var [index] = content to define 8. the default value is the string type. To define other types, declare must be used to define declare [-aixr] variable options and parameters:-: the variable named variable is defined as the array type-I: The variable named variable is defined as the integer type-x: The usage is the same as that of export, is to change the subsequent variable to the Environment sending volume;-r: sets the sending volume to the readonly type, and the sending volume cannot be changed, it cannot be unset. 3. Define the environment variable. If the variable needs to be executed in another subroutine, use export to make the variable Change to environment variable: export PATH 4. Cancel the variable unset paraname 5. Use env to list all environment variables in the Current shell environment. HOME represents the HOME Directory of the user. Which program does SHELL currently use in this environment? Linux uses/bin/bash HISTSIZE by default. commands we once issued can be recorded by the system, and the recorded "number of records" is set by this value. MAIL when we use the mail command to receive MAIL, the system will read the mail box file (mailbox ). PATH is the PATH where the file is searched. LANG encoding is used to set a RANDOM number between RANDOM 0 and 32767. 6. Use set to observe all variables. $: the PID echo $ in this shell shows your PID Number.?: If the return value of the previous execution command is correct, the return value is 0. 7. Variable change variable setting method description $ {Variable # keyword}. If the variable content from the beginning complies with the "keyword 』, delete the minimum matching data $ {Variable # keyword}. If the variable content from the beginning complies with the "keyword 』, delete the longest matching data $ {Variable % keyword}. If the variable content is forward from the end 』, delete the minimum matching data $ {Variable % keyword}. If the variable content is forward from the end 』, delete the longest matching data $ {Variable/old string/new string}. If the variable content matches the old string, the first old string is replaced by the new string $ {Variable/ /old string/new string} if the variable content conforms to the "Old string", "all old strings will be replaced by new strings" variable setting method str is not set as a Null String str has been set and non-empty var =$ {str-expr} var = expr var = $ str var =$ {str: -expr} Var = expr var = $ str var =$ {str + expr} var = expr var =$ {str: + expr} var = expr var =$ {str = expr} str = expr var = expr str unchanged var = $ str var =$ {str: = expr} str = expr var = expr str unchanged var = $ str var =$ {str? Expr} expr output to stderr var = $ str var =$ {str :? Expr} expr output to stderr var = $ str