Linux Shell programming learning notes log on to Shell, the Shell program automatically loaded after you log on to the system. Most Linux systems use/bin/bash as the shells that can be used by the Shell system supported by the default logon Shell/etc/shells file system, the last data record of cat/etc/shellsecho $ SHELL/etc/passwd in the/etc/shells file is the shell script written by the user login. Note: 1. the command is to analyze and execute 2. if you read the Enter symbol, you can start to execute the command line 3. you can use \ [Enter] for branch 4. # execute the/home/zack/shell script for annotation execution. sh: 1. run the following command: shell. sh files must have the r and x permissions. 2. run the following command in bash: bash shell. sh or sh shell. shshell. Sh only requires the r permission. 3. use source to execute, execute special characters in the parent program double quotation marks to allow reference, \ escape single quotes to prohibit reference, escape anti-apostrophes, or $ () replace the status value of the previous command with command output $? 0 is a normal, non-0 exception expr command, calculation expression such as: expr 45-32 expr 12/* 11 $ [] expression, formula replacement such: echo $[45 + 12] x = 45; y = 11; echo $ [x-y] variable increments, decrease let variable name + let variable name -- let variable name + = 2 RANDOM number echo $ RANDOMecho $ [RANDOM % 100] $ (seq 1 100) # seq is sequence (continuous) abbreviation, from 1 to 100 consecutive number seq first number last number seq first number increment last number generate random string head-n 1/dev/urandom | md5sum | cut-B 1-8 test command the test command is used to detect certain files or attributes in the system. The brackets "[]" are used for judgment, for example: ["$ HOME" = $ "MAIL"] ["$ yn" = "N"-o "$ yn" = "n"]-e existence-f Whether file-d is directory-r read permission read-w write permission write-x execution permission excution-z is empty-eq is equal to-ne not equal to-gt is greater than-lt less- ge is greater than or equal to-le is less than or equal! No script parameter scriptname opt1 opt2 opt3 opt4 $0 $1 $2 $3 $4 $ # number of parameters $ @ All content of the parameter if judgment statement if []; then elif []; thenfi case judgment 1. start with case and end with esac 2. each variable is enclosed in double quotes and ended with parentheses. the program section ends. use * to represent other values case $ variable names in <= the keyword is case, and there is also a rich front variable font size "the first variable content ") <= It is recommended that the content of each variable be enclosed by double quotation marks, and the keyword is parentheses). <= two consecutive semicolons are used at the end of each class deletion! "Second variable content") program segment; *) <= The Last variable content uses * to represent all other values, other Program Execution segments that do not contain the content of the first variable and the content of the second variable exit 1 ;; the function of esac in shell script must represent $0 by the function name at the beginning of the program, and the subsequent parameter is also $1, $2... in the loop while [condition] <= the state in the brackets is the begin do <= do is the beginning of the loop! Program section done <= done is the end of the loop until [condition] do program section done for var in con1 con2 con3... do program segment done for (initial value; limit value; execution step) do program segment done sh [-nvx] scripts. sh option parameter:-n: do not execute the script, only query syntax problems;-v: Before executing scloud, output the content of scripts to the screen;-x: displays the script content on the screen. This is a useful parameter! You can use sh-x script. sh to debug the program.