Basic knowledge of shell scripts

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

Insert picture description here
As a result of the experiment, edit the westos.sh script and press the f4 key to automatically add the script header.
Insert picture description here
2) Vim automatically adds the script header

vim /etc/vimrc

Insert picture description here
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

Insert picture description here

4. How to execute shell script

1) Manually specify the interpreter
sh script.sh
Insert picture description here
Insert picture description here
in the environment 2) Run the instructions in the shell directly in the current environment without opening a new shell
source script.sh
Insert picture description here
. Script.sh
Insert picture description here
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
Insert picture description here

Published 35 original articles · praised 0 · visits 1408

Guess you like

Origin blog.csdn.net/qq_44749796/article/details/105269411