1. Create shell script file Create file, add executable permission to file chmod +x file format: Specify the shell #! in the first line of the file /bin/bash NOTES: #开头的命令 (except #!/bin/bash in the first line) Display message: Echo command Quotation marks are not required by default, and if you need to display a string that contains one of the single or double quotation marks, you can use a different string to make the difference. echo command displays the string after the default line wrap, the-n option can be executed after the result of the next line of command is displayed The environment variable reference in ECHO is automatically recognized and replaced with the actual value $ (variable name) User variable: format: name=value, no spaces in the middle, The life cycle is the execution of the shell script, and the automatic deletion is done. Back quotes ('): Gets the return content of the command to be executed such as: times= ' Date ' &NBS P echo "The data is:" $times the data Is:mon Jan 31 20:2 3:25 EDT 2011 REDIRECT: OUTPUT redirect: command > OutputFile --overwrite write to file &NB Sp command >> outputfile --Append to file input redirection: Opposite to output redirection, using < or <<, less common piping: | , for the output of one command as input to another command, two commands for simultaneous execution 2, exit script View exit status code: $? Saved the result of the previous command execution, 0 for success, 1~255 for error Common status code--126: no permissions; 127: Command not found Exit command: Exit status code, Used to exit the shell script and specify an exit code
Shell Script Programming Basics