1. What is a shell
shell is an interpreter of commands in a script
2. The meaning of shell script
1. Record the command execution process and execution logic so that it can be repeated later.
2. The script can process the host in batches.
3. The script can process the host regularly.
3. How to create a shell script
#! / bin / bash ## Magic number, specify the interpreter in the current system
1) add script header by vim button
vim /etc/vimrc
As a result of the experiment, edit the westos.sh script and press the f4 key to automatically add the script header.
2) Vim automatically adds the script header
vim /etc/vimrc
Experimental results, when a new file ending in .sh or .scripts is created, the script header is automatically generated when the file is opened
vim test.sh
4. How to execute shell script
1) Manually specify the interpreter
sh script.sh
in the environment 2) Run the instructions in the shell directly in the current environment without opening a new shell
source script.sh
. Script.sh
3) Open the shell specified in the script and use this shell The command in the environment running script
chmod + x script.sh
/xxx/xxx/script.sh
./script.sh
5. How to debug the script
sh -x /mnt/test.sh