Linux ------- create Shell program and special characters, linux ------- shell
I. How to execute Shell scripts
Shell scripts are text files, so you can use any text file editor (such as vi and emacs) to create and edit scripts. The name of the Shell script file is not limited to the suffix name, usually without the suffix name or ". sh" suffix name.
Shell scripts can be executed in the following three ways:
(1) execute the script as an executable file:
By default, the script file generated in the text editor does not have the x permission, so it cannot be executed directly. After the r and x permissions are granted, the script can be read and executed as a Shell command. If the script is no longer stored in the default directory of the command, you must specify the script path name during execution. In the preceding example, the script hello is placed in the current directory. If the current directory is not the default path of the system, run it with./sayhello. Otherwise, run sayhello directly.
(2) Start a Shell sub-process to execute the script file:
$ Bash sayhello
(3) Let the Current Shell Process execute the script file:
Note: there is a space behind it!
"." Is an internal Shell command, and sayhello is its parameter. The "." command is used to read the file specified by the parameter and execute its content. This method is similar to the second method. The difference is that the current Shell process executes the script file.
Ii. Input/Output redirection
(1) additional redirection
">" Is an additional redirection character for the standard output. It redirects stdout or stderr to a file in the append mode. 1> or> indicates stdout additional redirection, 2> indicates stderr additional redirection.
Note: When the appended string contains spaces, use ""
(2) Use of the here document
"<" Is a special standard input redirection mechanism called "here document )". The format of the here document is:
<End tag string
It instructs Shell to pass the input line following this command line as the standard input of the command to the command until the end mark string is encountered.