Create a shell script
1. Use a text editor to create a text file
- The first line shell declaration must include the sequence:! #
Example:! # / Bin / bash - Add Comments: Comments begin with #
2. Run the script
- Give execute permissions, specified on the command line script absolute or relative path
- Directly run the interpreter, the script interpreter program as an argument
Script Specification
- The first line calls for the use of language in general
- Program name, to avoid changing the file name can not find the right file
- version number
- Time after the change
- Author Information
- The role of the program, and precautions
- Finally, a brief description of each version of the update
The basic structure of the script ▷
#!SHEBANG CONFIGURATION_VARIABLES FUNCTION_DEFINITIONS MAIN_CODE
shell script example
#!/bin/bash # ------------------------------------------ # Filename: hello.sh # Revision: 1.1 # Date: 2019/05/26 # Author: GUO # Email: [email protected] # Website: www.magedu.com # Description: This is the first script # Copyright: 2017 wang # License: GPL # ------------------------------------------ echo “hello world”
- Script Debugging
Syntax error detection script
bash -n /path/to/some_script
Debug executive
bash -x /path/to/some_script