Shell scripts are not used for shell programming for a while, and are a little unfamiliar at first. I have reviewed it recently. Just take a note. If you can help people in need, you will be satisfied ...... Let's just move it to the topic. 1. shell scripts are differentiated from lower-case www.2cto.com 2. Special Unix characters include: (; $? & * () [] ''+ Escape () 3. shell Comments start with #. 4. function Definition Function fuction_name () {Command to execute} is called directly using function_name. 5. control Structure 1) If... then statement If [test_command] ThenCommandsif2) If... then... else statement If [test_command] ThenCommandsElsecommandsif3) If... then... elif... then... (else) statement If [test_command] ThenCommandsElif [test_command] ThenCommandsElseCommandsFi4)... in statement For loop_varible in argument_listDoComm Andsdone5) while statement While waiting) until statement Until test_command_is_trueDoCommandsDone7) case statement Case $ variable inMatch_1) Commands_for_1; Match_2) Commands_for_2 ;;... *) # option for other valuesCommands_for_no_match; esac6.break, continue, exit, and return statement Break jump out of the entire loop body, and then execute the following code in vitro; Continue ends the cycle and continues the next cycle; exit exits the entire script. Generally, an integer (such as exit 0) is added to the end of the script and sent to the system as the Return code. Return is used to Return data in the function, or return a result to call function 7. here File is used to redirect input to an interactive shell script or program without user intervention. Program_name <LABLEProgram_input_1Program_input_2 .. program_input _ # LABLE Note: There is no blank between LABLE tags in the input line of the program, and the input must be the expected accurate data of the program, otherwise it may become invalid. 8. symbol command () in a subshell, run the command () enclosed in parentheses to evaluate and assign values to variables in a shell, and perform mathematical operations $ (()) evaluate the enclosed expression [] with the same value as the test Command [[] for string comparison $ () command replacement ''command replacement 9. command line parameters $0, $1, $2 ,..., $9 is the location parameter, and $0 points to the Command itself. Shift is used to move the location parameter to the left, for example, shift command $2 to $1. Shift adds a number to move multiple positions. For example, shift 3 makes $4 $1. Shift is a good way to process parameters at each location in the order listed by parameters. 10. Special parameter $ * specifies all command line parameters, which are of the same significance as $. The two parameters have different meanings only when double quotation marks are added. For example, "$ *" is used to obtain the entire parameter list as a parameter, and "$ @" is used to obtain the entire parameter list, and separate them into different parameters. $? Check the returned code. The return code of a successfully executed command is 0, and the Failure value is a non-0 value. 11. double quotation marks (single quotation marks) and '(button below esc) single quotation marks ''are used to reference the content. That is to say, the variable command statement uses the text body without any replacement; if double quotation marks are partially referenced, character replacement or command replacement is allowed. '(Press the button under esc) is used to execute a command or script and replace the output result, that is, replace the command. The same functions include $ (). In addition, if you want to re-read the value of a variable every time you use it, such as '$ pwd', the new value is re-read every time you use this variable. Www.2cto.com 12. The file permission and the suid (sgid) File Permission have three permissions: read, write, and execute. Set the file operation mode to always be a specific user (suid), or always as a specific group member (sgid) for execution. You can run the chmod command to modify the file permissions. 13. run the command Ssh user @ hostname command_to_execute on the remote host such as: ssh jack@192.168.1.3 "uptime" 14. set a trap when a program is forced to stop, an exit signal is called a trap ). In this way, we can execute the command when capturing the exit signal, for example, when capturing the exit signal, exit: Trap 'echo "nEXITTING on a trapped singal "; exit '1 2 3 15 note that kill-9 cannot be captured.. 15. view user information Who provides the user name, tty, Logon Time, and user logon location (IP) W for who extension for each login user, including job process time, total user process time, etc, but there is no user logon location information. Last displays the user name list information that has been logged on since the creation of the wtmp file, including the logon time, Exit Time, And tty. 16. The ps command displays information about the current system process. 17. communicate with users through the tr or typeset command in Wall, rwall, write, talk18. case-sensitive text. VALUES = "AFCDLD" Echo $ VALUES | tr '[A-Z] ''[a-z]' # converts uppercase to lowercase; tr' [a-z] ''[A-Z] 'converts lowercase to uppercase or www.2cto.com before VALUES using Typeset-l VALUES # converts uppercase to lowercase; typeset-u converts lowercase letters to uppercase letters. 19. the scheduled run script cronCrontab-e is used to add a scheduled script to the user cron table. For example, the script/usr/bin/test is executed at on Sunday, January 1, January 15. sh # minute (0-59) hour (0-23) Day (1-31) month (1-12) Week (0-6for Sunday-Saturday) 12 0 15 1 0/usr/bin/test. THE sh scheduled task can also use the at command. 20. the output control is silent, that is, no content is output to the screen: 2> & 1>/dev/null is output to the console specified by the system:> /dev/console21. parse the command line parameter getoptsGetopts optionstring VARIABLEOptionstring is a required parameter, which is separated by a colon. If no parameter is required, the colon can be omitted. If there is a colon Before optionstring, any unmatched? Getopts is used to parse the parameter and then use this parameter for different operations. For example, While getopts: s: m: h: d: p: TMDo Case $ TM in S) Do something; M) Do something ;;...?) Exit 1; Esac22. process the file LINE by LINE While read LINEDoEcho "$ LINE" Done <$ FILENAME23. create the select menu in Select menu in Yes No QuitDoCase $ menu inYes) Do something ;; no) Do something; Quit) Break; *) Do something; Esacdone