The simple thing is to write some shell syntax and commands in it, plus regular expressions, pipeline commands, and data flow redirection to achieve the purpose we want.
Shell scripts is a good tool for system administration, but it is not fast enough to handle a large number of computations and uses more CPU resources.
One. The first scripts is written and executed
Suppose we write the first scripts file named Shell.sh and execute the following methods:
(1) Direct command execution: The shell.sh file must have Rx (Read and execute) permission.
Absolute path:/home/chuiyuan/shell.sh
Relative path: Under/home/chuiyuan, use./shell.sh
Variable path function: Place shell.sh under Path specified by path, such as ~/bin (this directory is set by itself)
(2) Execute with bash: You can only have Read permission at this time.
Executed via bash shell.sh or sh shell.sh. This means that the system wants to execute commands in this file with bash functionality.
Shell files can use-N and-X to view the syntax.
Example:
The first line declares that we are using the bash syntax, which must have the ability to load bash-related configuration files (typically the Non-login Shell's ~/.BASHRC) and execute bash to enable our commands to execute. Otherwise the program will not know what shell to use.
The environment variable is set here so that the program can execute some external commands directly while it is in progress, without having to write absolute paths.
The last line indicates that the program is terminated and a 0 is returned to the system to indicate successful execution. We can also use Exit N for customization.
Note that the permissions for the program are read-only at this time
So you can only use bash to perform
To use a direct path to execute, change the permissions
CHAPTE13: Learning shell Scripts (1) Simple shell scripts