first, how to execute the shell script
Shell scripts are text files, so you can create and edit scripts with any text file editor (such as Vi,emacs, etc.). The name of the shell script file does not have a qualified suffix name, usually without a suffix name or with a ". Sh" suffix.
Shell scripts are executed in the following 3 ways:
(1) Execute the script as an executable file:
Script files generated with a text editor do not have x permissions by default, and they are not directly executed. Given R and X permissions, the script can be read and executed like a normal shell command. If the script is no longer stored in the default directory of the command, you need to execute the path name of the specified script. In the example above, the script hello is placed in the current directory, if the current directory is not the system default path will be used./sayhello to run, or directly execute SayHello can.
(2) Start a shell subprocess to execute the script file:
$bash SayHello
(3) Let the current shell process execute the script file:
Note that there are spaces behind!
“.” is the shell internal Command, SayHello is its argument. “.” The function of the command is to read the file specified by the parameter and execute its contents. This is done in a similar way to the second, except that this is done by the current shell process to execute the script file.
II. Input/Output redirection
(1) Additional redirects
">>" is a standard output additional redirect that redirects a standard output stdout or a standard error output stderr to a file in an append manner. 1>> or >> indicates that the stdout additional redirection,2>> represents stderr additional redirection.
Note: When the appended string has a space, use ""
(2) Use of Here documents
"<<" is a special standard input redirection mechanism called "here Document". The presentation format for the here document is:
<< end Tag String
Its purpose is to instruct the shell to pass the input line following this command line as the standard input to the command until the end tag string is encountered.
Linux-------The creation of Shell programs and special characters